Skip to content

Commit 15b8dd9

Browse files
committed
Make Injective and HyperView parameter attributes
instead of function attributes. Rewrite Tapir alias analysis to be more independent of BasicAliasAnalysis. In the future it should be a separate alias analysis pass. Add __tapir_frame builtin to get current frame descriptor. Pass __tapir_frame as an argument to hyperobject view lookup. Remove never-used hyper_token builtin and intrinsic.
1 parent 9ce0f85 commit 15b8dd9

26 files changed

+414
-375
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4156,21 +4156,14 @@ def StrandMalloc : InheritableAttr {
41564156
}
41574157

41584158
def Injective : InheritableAttr {
4159-
// TODO: Associate this with a single argument, not the function.
41604159
let Spellings = [Clang<"injective">];
4161-
let Subjects = SubjectList<[Function]>;
4160+
let Subjects = SubjectList<[ParmVar]>;
41624161
let Documentation = [Undocumented];
41634162
}
41644163

41654164
def HyperView : InheritableAttr {
41664165
let Spellings = [Clang<"hyper_view">];
4167-
let Subjects = SubjectList<[FunctionLike]>;
4168-
let Documentation = [StrandMallocDocs];
4169-
}
4170-
4171-
def HyperToken : InheritableAttr {
4172-
let Spellings = [Clang<"hyper_token">];
4173-
let Subjects = SubjectList<[FunctionLike]>;
4166+
let Subjects = SubjectList<[ParmVar]>;
41744167
let Documentation = [StrandMallocDocs];
41754168
}
41764169

clang/include/clang/Basic/Builtins.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,8 @@ BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
17211721
// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
17221722
LANGBUILTIN(__arithmetic_fence, "v.", "tE", ALL_LANGUAGES)
17231723

1724+
BUILTIN(__tapir_frame, "v*", "n")
1725+
17241726
// Tapir. Rewriting of reducer references happens during sema
17251727
// and needs a builtin to carry the information to codegen.
17261728
BUILTIN(__hyper_lookup, "v*vC*z.", "nU")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5429,15 +5429,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
54295429
Str.getPointer(), Zeros);
54305430
return RValue::get(Ptr);
54315431
}
5432+
case Builtin::BI__tapir_frame: {
5433+
Function *FF = CGM.getIntrinsic(Intrinsic::tapir_frame);
5434+
return RValue::get(Builder.CreateCall(FF, {}));
5435+
}
54325436
case Builtin::BI__hyper_lookup: {
5437+
Function *TF = CGM.getIntrinsic(Intrinsic::tapir_frame);
5438+
llvm::Value *Frame = Builder.CreateCall(TF, {});
54335439
llvm::Value *Size = EmitScalarExpr(E->getArg(1));
54345440
Function *F = CGM.getIntrinsic(Intrinsic::hyper_lookup, Size->getType());
54355441
llvm::Value *Ptr = EmitScalarExpr(E->getArg(0));
54365442
llvm::Value *Identity = EmitScalarExpr(E->getArg(2));
54375443
llvm::Value *Reduce = EmitScalarExpr(E->getArg(3));
5438-
return RValue::get(Builder.CreateCall(
5439-
F, {Ptr, Size, Builder.CreateBitCast(Identity, VoidPtrTy),
5440-
Builder.CreateBitCast(Reduce, VoidPtrTy)}));
5444+
CallInst *Call =
5445+
Builder.CreateCall(F,
5446+
{Frame, Ptr, Size,
5447+
Builder.CreateBitCast(Identity, VoidPtrTy),
5448+
Builder.CreateBitCast(Reduce, VoidPtrTy)});
5449+
// TODO: These should be added automatically based on the function type.
5450+
Call->addParamAttr(1, Attribute::Injective);
5451+
Call->addParamAttr(1, Attribute::HyperView);
5452+
return RValue::get(Call);
54415453
}
54425454
}
54435455
IsSpawnedScope SpawnedScp(this);

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9364,9 +9364,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
93649364
case ParsedAttr::AT_HyperView:
93659365
handleSimpleAttribute<HyperViewAttr>(S, D, AL);
93669366
break;
9367-
case ParsedAttr::AT_HyperToken:
9368-
handleSimpleAttribute<HyperTokenAttr>(S, D, AL);
9369-
break;
93709367
case ParsedAttr::AT_ReducerUnregister:
93719368
handleSimpleAttribute<ReducerUnregisterAttr>(S, D, AL);
93729369
break;

clang/test/Cilk/hyper-array-extern-1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int read_array_hyper(unsigned i)
1010
{
1111
return x[i];
1212
// CHECK: %[[ARRAYIDX:.+]] = getelementptr inbounds
13-
// CHECK: %[[VIEWRAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %[[ARRAYIDX]], i64 4, ptr null, ptr null)
13+
// CHECK: %[[VIEWRAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[ARRAYIDX]], i64 4, ptr null, ptr null)
1414
// CHECK-NOT: call ptr @llvm.hyper.lookup
1515
// CHECK: %[[VAL:.+]] = load i32, ptr %[[VIEWRAW]]
1616
// CHECK: ret i32 %[[VAL]]

clang/test/Cilk/hyper-assign.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ extern long _Hyperobject x, _Hyperobject y;
66

77
long chain_assign()
88
{
9-
// CHECK: %[[Y1RAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
9+
// CHECK: %[[Y1RAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
1010
// CHECK: %[[Y1VAL:.+]] = load i64, ptr %[[Y1RAW]]
11-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
11+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
1212
// CHECK: store i64 %[[Y1VAL]]
13-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
14-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
13+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
14+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
1515
return x = y = x = y;
1616
}
1717

1818
long simple_assign(long val)
1919
{
20-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
20+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
2121
// CHECK-NOT: call ptr @llvm.hyper.lookup
2222
// CHECK: store i64
2323
return x = val;
@@ -26,11 +26,11 @@ long simple_assign(long val)
2626
long subtract()
2727
{
2828
// The order is not fixed here.
29-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
29+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
3030
// CHECK: load i64
3131
// CHECK: add nsw i64 %[[Y:.+]], 1
3232
// CHECK: store i64
33-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
33+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
3434
// CHECK: load i64
3535
// CHECK: sub nsw
3636
// CHECK: store i64

clang/test/Cilk/hyper-complex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern __complex__ float _Hyperobject c;
77
// CHECK-LABEL: get_real
88
float get_real()
99
{
10-
// CHECK: %[[RAW1:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
10+
// CHECK: %[[RAW1:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
1111
// CHECK: %[[FIELD1:.+]] = getelementptr inbounds { float, float }, ptr %[[RAW1]], i32 0, i32 0
1212
// CHECK: %[[RET1:.+]] = load float, ptr %[[FIELD1]]
1313
// CHECK: ret float %[[RET1]]
@@ -16,7 +16,7 @@ float get_real()
1616
// CHECK-LABEL: get_imag
1717
float get_imag()
1818
{
19-
// CHECK: %[[RAW2:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
19+
// CHECK: %[[RAW2:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
2020
// CHECK: %[[FIELD2:.+]] = getelementptr inbounds { float, float }, ptr %[[RAW2]], i32 0, i32 1
2121
// CHECK: load float, ptr %[[FIELD2]]
2222
// CHECK: ret float
@@ -27,7 +27,7 @@ float get_imag()
2727
float get_abs()
2828
{
2929
// Only one call to llvm.hyper.lookup.
30-
// CHECK: @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
30+
// CHECK: @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
3131
// CHECK-NOT: @llvm.hyper.lookup
3232
// CHECK: call float @cabsf
3333
// CHECK: ret float

clang/test/Cilk/hyper-copy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ extern struct S b __attribute__((aligned(8)));
99
// CHECK-LABEL: scopy
1010
void scopy()
1111
{
12-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @a, i64 8, ptr null, ptr null)
12+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @a, i64 8, ptr null, ptr null)
1313
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 @b,
14-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @a, i64 8, ptr null, ptr null)
14+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @a, i64 8, ptr null, ptr null)
1515
// CHECK: call void @llvm.memcpy.p0.p0.i64
1616
// CHECK: ret void
1717
b = a;

clang/test/Cilk/hyper-template.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ template<typename T> struct S { T member; };
55
S<long> _Hyperobject S_long;
66

77
// CHECK-LABEL: @_Z1fv
8-
// CHECK: %0 = call ptr @llvm.hyper.lookup.i64(ptr @S_long, i64 8, ptr null, ptr null)
8+
// CHECK: %0 = call ptr @llvm.tapir.frame()
9+
// CHECK: %1 = call ptr @llvm.hyper.lookup.i64(ptr %0, ptr hyper_view injective @S_long, i64 8, ptr null, ptr null)
910
// CHECK-NOT: call ptr @llvm.hyper.lookup
1011
// CHECK: getelementptr
1112
// CHECK: %[[RET:.+]] = load i64

clang/test/Cilk/hyper-unary.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ void function1()
1111
{
1212
// CHECK: store i32 1, ptr %[[Y:.+]],
1313
int _Hyperobject y = 1;
14-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
14+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
1515
// CHECK: load i32
16-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
16+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
1717
// CHECK: load i32
1818
(void)x; (void)y;
1919
}
@@ -23,9 +23,9 @@ void function2()
2323
{
2424
// CHECK: store i32 1, ptr %[[Y:.+]],
2525
int _Hyperobject y = 1;
26-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
26+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
2727
// CHECK: load i32
28-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
28+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
2929
// CHECK: load i32
3030
(void)!x; (void)!y;
3131
}
@@ -35,18 +35,18 @@ void function3()
3535
{
3636
// CHECK: store i32 1, ptr %[[Y:.+]],
3737
int _Hyperobject y = 1;
38-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
38+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
3939
// CHECK: load i32
40-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
40+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
4141
// CHECK: load i32
4242
(void)-x; (void)-y;
43-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
43+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
4444
// CHECK: load i32
45-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
45+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
4646
// CHECK: load i32
4747
(void)~x; (void)~y;
4848
// CHECK: %[[XP:.+]] = load ptr, ptr @xp
49-
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[XP]], i64 4, ptr null, ptr null)
49+
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[XP]], i64 4, ptr null, ptr null)
5050
// CHECK: load i32
5151
(void)*xp;
5252
}

0 commit comments

Comments
 (0)