Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New builtin to get stack_frame object #208

Draft
wants to merge 1 commit into
base: dev/17.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -4227,21 +4227,14 @@ def StrandMalloc : InheritableAttr {
}

def Injective : InheritableAttr {
// TODO: Associate this with a single argument, not the function.
let Spellings = [Clang<"injective">];
let Subjects = SubjectList<[Function]>;
let Subjects = SubjectList<[ParmVar]>;
let Documentation = [Undocumented];
}

def HyperView : InheritableAttr {
let Spellings = [Clang<"hyper_view">];
let Subjects = SubjectList<[FunctionLike]>;
let Documentation = [StrandMallocDocs];
}

def HyperToken : InheritableAttr {
let Spellings = [Clang<"hyper_token">];
let Subjects = SubjectList<[FunctionLike]>;
let Subjects = SubjectList<[ParmVar]>;
let Documentation = [StrandMallocDocs];
}

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,8 @@ BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
LANGBUILTIN(__arithmetic_fence, "v.", "tE", ALL_LANGUAGES)

BUILTIN(__tapir_frame, "v*", "n")

// Tapir. Rewriting of reducer references happens during sema
// and needs a builtin to carry the information to codegen.
BUILTIN(__hyper_lookup, "v*vC*z.", "nU")
Expand Down
18 changes: 15 additions & 3 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5536,15 +5536,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Str.getPointer(), Zeros);
return RValue::get(Ptr);
}
case Builtin::BI__tapir_frame: {
Function *FF = CGM.getIntrinsic(Intrinsic::tapir_frame);
return RValue::get(Builder.CreateCall(FF, {}));
}
case Builtin::BI__hyper_lookup: {
Function *TF = CGM.getIntrinsic(Intrinsic::tapir_frame);
llvm::Value *Frame = Builder.CreateCall(TF, {});
llvm::Value *Size = EmitScalarExpr(E->getArg(1));
Function *F = CGM.getIntrinsic(Intrinsic::hyper_lookup, Size->getType());
llvm::Value *Ptr = EmitScalarExpr(E->getArg(0));
llvm::Value *Identity = EmitScalarExpr(E->getArg(2));
llvm::Value *Reduce = EmitScalarExpr(E->getArg(3));
return RValue::get(Builder.CreateCall(
F, {Ptr, Size, Builder.CreateBitCast(Identity, VoidPtrTy),
Builder.CreateBitCast(Reduce, VoidPtrTy)}));
CallInst *Call =
Builder.CreateCall(F,
{Frame, Ptr, Size,
Builder.CreateBitCast(Identity, VoidPtrTy),
Builder.CreateBitCast(Reduce, VoidPtrTy)});
// TODO: These should be added automatically based on the function type.
Call->addParamAttr(1, Attribute::Injective);
Call->addParamAttr(1, Attribute::HyperView);
return RValue::get(Call);
}
}
IsSpawnedScope SpawnedScp(this);
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9510,9 +9510,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
case ParsedAttr::AT_HyperView:
handleSimpleAttribute<HyperViewAttr>(S, D, AL);
break;
case ParsedAttr::AT_HyperToken:
handleSimpleAttribute<HyperTokenAttr>(S, D, AL);
break;
case ParsedAttr::AT_ReducerUnregister:
handleSimpleAttribute<ReducerUnregisterAttr>(S, D, AL);
break;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Cilk/hyper-array-extern-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int read_array_hyper(unsigned i)
{
return x[i];
// CHECK: %[[ARRAYIDX:.+]] = getelementptr inbounds
// CHECK: %[[VIEWRAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %[[ARRAYIDX]], i64 4, ptr null, ptr null)
// CHECK: %[[VIEWRAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[ARRAYIDX]], i64 4, ptr null, ptr null)
// CHECK-NOT: call ptr @llvm.hyper.lookup
// CHECK: %[[VAL:.+]] = load i32, ptr %[[VIEWRAW]]
// CHECK: ret i32 %[[VAL]]
Expand Down
14 changes: 7 additions & 7 deletions clang/test/Cilk/hyper-assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ extern long _Hyperobject x, _Hyperobject y;

long chain_assign()
{
// CHECK: %[[Y1RAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
// CHECK: %[[Y1RAW:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
// CHECK: %[[Y1VAL:.+]] = load i64, ptr %[[Y1RAW]]
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
// CHECK: store i64 %[[Y1VAL]]
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
return x = y = x = y;
}

long simple_assign(long val)
{
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
// CHECK-NOT: call ptr @llvm.hyper.lookup
// CHECK: store i64
return x = val;
Expand All @@ -26,11 +26,11 @@ long simple_assign(long val)
long subtract()
{
// The order is not fixed here.
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @y, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @y, i64 8, ptr null, ptr null)
// CHECK: load i64
// CHECK: add nsw i64 %[[Y:.+]], 1
// CHECK: store i64
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 8, ptr null, ptr null)
// CHECK: load i64
// CHECK: sub nsw
// CHECK: store i64
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Cilk/hyper-complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern __complex__ float _Hyperobject c;
// CHECK-LABEL: get_real
float get_real()
{
// CHECK: %[[RAW1:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
// CHECK: %[[RAW1:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
// CHECK: %[[FIELD1:.+]] = getelementptr inbounds { float, float }, ptr %[[RAW1]], i32 0, i32 0
// CHECK: %[[RET1:.+]] = load float, ptr %[[FIELD1]]
// CHECK: ret float %[[RET1]]
Expand All @@ -16,7 +16,7 @@ float get_real()
// CHECK-LABEL: get_imag
float get_imag()
{
// CHECK: %[[RAW2:.+]] = call ptr @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
// CHECK: %[[RAW2:.+]] = call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
// CHECK: %[[FIELD2:.+]] = getelementptr inbounds { float, float }, ptr %[[RAW2]], i32 0, i32 1
// CHECK: load float, ptr %[[FIELD2]]
// CHECK: ret float
Expand All @@ -27,7 +27,7 @@ float get_imag()
float get_abs()
{
// Only one call to llvm.hyper.lookup.
// CHECK: @llvm.hyper.lookup.i64(ptr @c, i64 8, ptr null, ptr null)
// CHECK: @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @c, i64 8, ptr null, ptr null)
// CHECK-NOT: @llvm.hyper.lookup
// CHECK: call float @cabsf
// CHECK: ret float
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Cilk/hyper-copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ extern struct S b __attribute__((aligned(8)));
// CHECK-LABEL: scopy
void scopy()
{
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @a, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @a, i64 8, ptr null, ptr null)
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 @b,
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @a, i64 8, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @a, i64 8, ptr null, ptr null)
// CHECK: call void @llvm.memcpy.p0.p0.i64
// CHECK: ret void
b = a;
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Cilk/hyper-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ template<typename T> struct S { T member; };
S<long> _Hyperobject S_long;

// CHECK-LABEL: @_Z1fv
// CHECK: %0 = call ptr @llvm.hyper.lookup.i64(ptr @S_long, i64 8, ptr null, ptr null)
// CHECK: %0 = call ptr @llvm.tapir.frame()
// CHECK: %1 = call ptr @llvm.hyper.lookup.i64(ptr %0, ptr hyper_view injective @S_long, i64 8, ptr null, ptr null)
// CHECK-NOT: call ptr @llvm.hyper.lookup
// CHECK: getelementptr
// CHECK: %[[RET:.+]] = load i64
Expand Down
18 changes: 9 additions & 9 deletions clang/test/Cilk/hyper-unary.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ void function1()
{
// CHECK: store i32 1, ptr %[[Y:.+]],
int _Hyperobject y = 1;
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
// CHECK: load i32
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
// CHECK: load i32
(void)x; (void)y;
}
Expand All @@ -23,9 +23,9 @@ void function2()
{
// CHECK: store i32 1, ptr %[[Y:.+]],
int _Hyperobject y = 1;
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
// CHECK: load i32
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
// CHECK: load i32
(void)!x; (void)!y;
}
Expand All @@ -35,18 +35,18 @@ void function3()
{
// CHECK: store i32 1, ptr %[[Y:.+]],
int _Hyperobject y = 1;
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
// CHECK: load i32
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
// CHECK: load i32
(void)-x; (void)-y;
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr @x, i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective @x, i64 4, ptr null, ptr null)
// CHECK: load i32
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[Y]], i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[Y]], i64 4, ptr null, ptr null)
// CHECK: load i32
(void)~x; (void)~y;
// CHECK: %[[XP:.+]] = load ptr, ptr @xp
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %[[XP]], i64 4, ptr null, ptr null)
// CHECK: call ptr @llvm.hyper.lookup.i64(ptr %{{[0-9]+}}, ptr hyper_view injective %[[XP]], i64 4, ptr null, ptr null)
// CHECK: load i32
(void)*xp;
}
29 changes: 29 additions & 0 deletions clang/test/Cilk/tapir-frame.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clang_cc1 %s -x c -O1 -fopencilk -mllvm -use-opencilk-runtime-bc=false -mllvm -debug-abi-calls=true -verify -S -emit-llvm -o - | FileCheck %s
// expected-no-diagnostics

// CHECK-LABEL: zero
int zero()
{
return __tapir_frame() != 0;
// CHECK: ret i32 0
}

// CHECK-LABEL: one
int one()
{
extern void f(int);
_Cilk_spawn f(0);
_Cilk_spawn f(1);
// CHECK: ret i32 1
return __tapir_frame() != 0;
}

// CHECK-LABEL: function3
int function3()
{
extern void f(int);
extern int g(void *);
_Cilk_spawn f(0);
// CHECK: call i32 @g(ptr noundef nonnull %__cilkrts_sf)
return g(__tapir_frame());
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@
// CHECK-NEXT: GNUInline (SubjectMatchRule_function)
// CHECK-NEXT: HIPManaged (SubjectMatchRule_variable)
// CHECK-NEXT: Hot (SubjectMatchRule_function)
// CHECK-NEXT: HyperToken (SubjectMatchRule_hasType_functionType)
// CHECK-NEXT: HyperView (SubjectMatchRule_hasType_functionType)
// CHECK-NEXT: HyperView (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: IBAction (SubjectMatchRule_objc_method_is_instance)
// CHECK-NEXT: IFunc (SubjectMatchRule_function)
// CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
// CHECK-NEXT: Injective (SubjectMatchRule_function)
// CHECK-NEXT: Injective (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
// CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
// CHECK-NEXT: Leaf (SubjectMatchRule_function)
Expand Down
8 changes: 6 additions & 2 deletions llvm/include/llvm/Analysis/BasicAliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ class BasicAAResult : public AAResultBase {
AliasResult aliasCheck(const Value *V1, LocationSize V1Size, const Value *V2,
LocationSize V2Size, AAQueryInfo &AAQI,
const Instruction *CtxI);
AliasResult aliasCheckTapir(const Value *V1, const Value *V2,
LocationSize Size, AAQueryInfo &AAQI,
const Instruction *CtxI);

AliasResult aliasCheckRecursive(const Value *V1, LocationSize V1Size,
const Value *V2, LocationSize V2Size,
AAQueryInfo &AAQI, const Value *O1,
const Value *O2);

AliasResult checkInjectiveArguments(const Value *V1, const Value *O1,
const Value *V2, const Value *O2,
const Value *getViewClass(const CallBase *V, AAQueryInfo &AAQI);
AliasResult checkInjectiveArguments(const CallBase *C1, const CallBase *C2,
AAQueryInfo &AAQI);

};

/// Analysis pass providing a never-invalidated alias analysis result.
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Attributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def FnRetThunkExtern : EnumAttr<"fn_ret_thunk_extern", [FnAttr]>;
def InAlloca : TypeAttr<"inalloca", [ParamAttr]>;

/// Distinct arguments to this function yield distinct return values.
def Injective : EnumAttr<"injective", [FnAttr]>;
def Injective : EnumAttr<"injective", [ParamAttr]>;

/// Source said inlining was desirable.
def InlineHint : EnumAttr<"inlinehint", [FnAttr]>;
Expand Down Expand Up @@ -222,7 +222,7 @@ def ReadNone : EnumAttr<"readnone", [ParamAttr]>;
def ReadOnly : EnumAttr<"readonly", [ParamAttr]>;

/// Tapir reducer-related attributes.
def HyperView : EnumAttr<"hyper_view", [FnAttr]>;
def HyperView : EnumAttr<"hyper_view", [ParamAttr]>;
def ReducerRegister : EnumAttr<"reducer_register", [FnAttr]>;
def ReducerUnregister : EnumAttr<"reducer_unregister", [FnAttr]>;

Expand Down
Loading