Skip to content

Commit 48cffd8

Browse files
committed
XXX
1 parent 9d0a784 commit 48cffd8

File tree

14 files changed

+36
-32
lines changed

14 files changed

+36
-32
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,6 @@ def CIR_InlineAttr : CIR_EnumAttr<CIR_InlineKind, "inline"> {
12221222
// Unit Function Attributes
12231223
//===----------------------------------------------------------------------===//
12241224

1225-
def CIR_OptNoneAttr : CIR_UnitAttr<"OptNone", "optnone"> {
1226-
let storageType = [{ OptNoneAttr }];
1227-
}
1228-
12291225
def CIR_NoThrowAttr : CIR_UnitAttr<"NoThrow", "nothrow"> {
12301226
let storageType = [{ NoThrowAttr }];
12311227
}

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,7 @@ def FuncOp : CIR_Op<"func", [
41014101
UnitAttr:$coroutine,
41024102
UnitAttr:$lambda,
41034103
UnitAttr:$no_proto,
4104+
UnitAttr:$opt_none,
41044105
UnitAttr:$dso_local,
41054106
DefaultValuedAttr<
41064107
CIR_GlobalLinkageKind, "GlobalLinkageKind::ExternalLinkage"

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,8 +2938,7 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(const Decl *decl,
29382938
} else if ((shouldAddOptNone || decl->hasAttr<OptimizeNoneAttr>()) &&
29392939
!isAlwaysInline) {
29402940
// Add optnone, but do so only if the function isn't always_inline.
2941-
auto optNoneAttr = cir::OptNoneAttr::get(&getMLIRContext());
2942-
attrs.set(optNoneAttr.getMnemonic(), optNoneAttr);
2941+
f.setOptNone(true);
29432942

29442943
// OptimizeNone implies noinline; we should not be inlining such functions.
29452944
auto noInlineAttr =

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,7 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26492649
auto lambdaNameAttr = getLambdaAttrName(state.name);
26502650
auto visNameAttr = getSymVisibilityAttrName(state.name);
26512651
auto noProtoNameAttr = getNoProtoAttrName(state.name);
2652+
auto optNoneNameAttr = getOptNoneAttrName(state.name);
26522653
auto visibilityNameAttr = getGlobalVisibilityAttrName(state.name);
26532654
auto dsoLocalNameAttr = getDsoLocalAttrName(state.name);
26542655
auto annotationsNameAttr = getAnnotationsAttrName(state.name);
@@ -2662,6 +2663,8 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26622663
state.addAttribute(lambdaNameAttr, parser.getBuilder().getUnitAttr());
26632664
if (parser.parseOptionalKeyword(noProtoNameAttr).succeeded())
26642665
state.addAttribute(noProtoNameAttr, parser.getBuilder().getUnitAttr());
2666+
if (parser.parseOptionalKeyword("optnone").succeeded())
2667+
state.addAttribute(optNoneNameAttr, parser.getBuilder().getUnitAttr());
26652668

26662669
// TODO: Missing comdat
26672670
assert(!cir::MissingFeatures::setComdat());
@@ -2898,6 +2901,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
28982901
if (getNoProto())
28992902
p << " no_proto";
29002903

2904+
if (getOptNone())
2905+
p << " optnone";
2906+
29012907
if (getComdat())
29022908
p << " comdat";
29032909

@@ -2946,8 +2952,8 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
29462952
getFunctionTypeAttrName(), getGlobalCtorPriorityAttrName(),
29472953
getGlobalDtorPriorityAttrName(), getLambdaAttrName(),
29482954
getLinkageAttrName(), getCallingConvAttrName(), getNoProtoAttrName(),
2949-
getSymVisibilityAttrName(), getArgAttrsAttrName(), getResAttrsAttrName(),
2950-
getComdatAttrName(), getGlobalVisibilityAttrName(),
2955+
getOptNoneAttrName(), getSymVisibilityAttrName(), getArgAttrsAttrName(),
2956+
getResAttrsAttrName(), getComdatAttrName(), getGlobalVisibilityAttrName(),
29512957
getAnnotationsAttrName(), getCxxSpecialMemberAttrName()});
29522958

29532959
if (auto aliaseeName = getAliasee()) {

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,7 @@ void CIRToLLVMFuncOpLowering::lowerFuncAttributes(
23702370
name == func.getFunctionTypeAttrName() ||
23712371
name == getLinkageAttrNameString() ||
23722372
name == func.getCallingConvAttrName() ||
2373+
name == func.getOptNoneAttrName() ||
23732374
name == func.getDsoLocalAttrName() ||
23742375
(filterArgAndResAttrs && (name == func.getArgAttrsAttrName() ||
23752376
name == func.getResAttrsAttrName())))
@@ -2525,6 +2526,9 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
25252526
getContext(), lowerCIRVisibilityToLLVMVisibility(
25262527
op.getGlobalVisibilityAttr().getValue())));
25272528

2529+
// Handle optnone attribute
2530+
fn.setOptimizeNone(op.getOptNone());
2531+
25282532
rewriter.inlineRegionBefore(op.getBody(), fn.getBody(), fn.end());
25292533
if (failed(rewriter.convertRegionTypes(&fn.getBody(), *typeConverter,
25302534
&signatureConversion)))

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ class CIRDialectLLVMIRTranslationInterface
110110
llvmFunc->addFnAttr(llvm::Attribute::InlineHint);
111111
else
112112
llvm_unreachable("Unknown inline kind");
113-
} else if (mlir::dyn_cast<cir::OptNoneAttr>(attr.getValue())) {
114-
llvmFunc->addFnAttr(llvm::Attribute::OptimizeNone);
115113
} else if (mlir::dyn_cast<cir::NoThrowAttr>(attr.getValue())) {
116114
llvmFunc->addFnAttr(llvm::Attribute::NoUnwind);
117115
} else if (mlir::dyn_cast<cir::ConvergentAttr>(attr.getValue())) {

clang/test/CIR/CodeGen/call-extra-attrs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ int s2(int a, int b) {
1818
return s1(a, b);
1919
}
2020

21-
// CIR: #fn_attr = #cir<extra({inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone})>
21+
// CIR: #fn_attr = #cir<extra({inline = #cir.inline<no>, nothrow = #cir.nothrow})>
2222
// CIR: #fn_attr1 = #cir<extra({nothrow = #cir.nothrow})>
2323

24-
// CIR: cir.func {{.*}} @_Z2s0ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
25-
// CIR: cir.func {{.*}} @_Z2s1ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
24+
// CIR: cir.func optnone {{.*}} @_Z2s0ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
25+
// CIR: cir.func optnone {{.*}} @_Z2s1ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
2626
// CIR: cir.call @_Z2s0ii(%{{.*}}, %{{.*}}) : ({{.*}}, {{.*}}) -> {{.*}} extra(#fn_attr1)
27-
// CIR: cir.func {{.*}} @_Z2s2ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
27+
// CIR: cir.func optnone {{.*}} @_Z2s2ii(%{{.*}}, %{{.*}}) -> {{.*}} extra(#fn_attr)
2828
// CHECK-NOT: cir.call @_Z2s1ii(%{{.*}}, %{{.*}}) : ({{.*}}, {{.*}}) -> {{.*}} extra(#fn_attr{{.*}})
2929

3030
// LLVM: define dso_local i32 @_Z2s0ii(i32 %0, i32 %1) #[[#ATTR1:]]

clang/test/CIR/CodeGen/conditional-cleanup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace test7 {
8282

8383
// CIR_EH-DAG: #[[$ATTR_0:.+]] = #cir.bool<false> : !cir.bool
8484
// CIR_EH-DAG: #[[$ATTR_1:.+]] = #cir<extra({nothrow = #cir.nothrow})>
85-
// CIR_EH-DAG: #[[$ATTR_2:.+]] = #cir<extra({inline = #cir.inline<no>, optnone = #cir.optnone})>
85+
// CIR_EH-DAG: #[[$ATTR_2:.+]] = #cir<extra({inline = #cir.inline<no>})>
8686
// CIR_EH-DAG: #[[$ATTR_3:.+]] = #cir.bool<true> : !cir.bool
8787

8888
// CIR_EH-LABEL: @_ZN5test74testEv

clang/test/CIR/CodeGen/dynamic-cast.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module @"/Users/henrichlauko/src/clangir/clang/test/CIR/CodeGen/dynamic-cast.cpp
2121
cir.global constant external @_ZTI7Derived = #cir.typeinfo<{#cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2 : i32]> : !cir.ptr<!u8i>, #cir.global_view<@_ZTS7Derived> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>}> : !rec_anon_struct {alignment = 8 : i64} loc(#loc28)
2222
cir.func private @__dynamic_cast(!cir.ptr<!void>, !cir.ptr<!u8i>, !cir.ptr<!u8i>, !s64i) -> !cir.ptr<!void> loc(#loc)
2323
cir.func private @__cxa_bad_cast() loc(#loc)
24-
cir.func dso_local @_Z8ptr_castP4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc5, #loc6])) -> !cir.ptr<!rec_Derived> {inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone} {
24+
cir.func dso_local optnone @_Z8ptr_castP4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc5, #loc6])) -> !cir.ptr<!rec_Derived> {inline = #cir.inline<no>, nothrow = #cir.nothrow} {
2525
%0 = cir.alloca !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>>, ["b", init] {alignment = 8 : i64} loc(#loc30)
2626
%1 = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["__retval"] {alignment = 8 : i64} loc(#loc4)
2727
cir.store %arg0, %0 : !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>> loc(#loc7)
@@ -43,7 +43,7 @@ module @"/Users/henrichlauko/src/clangir/clang/test/CIR/CodeGen/dynamic-cast.cpp
4343
%5 = cir.load %1 : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived> loc(#loc31)
4444
cir.return %5 : !cir.ptr<!rec_Derived> loc(#loc31)
4545
} loc(#loc29)
46-
cir.func dso_local @_Z8ref_castR4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc12, #loc13])) -> !cir.ptr<!rec_Derived> {inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone} {
46+
cir.func dso_local optnone @_Z8ref_castR4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc12, #loc13])) -> !cir.ptr<!rec_Derived> {inline = #cir.inline<no>, nothrow = #cir.nothrow} {
4747
%0 = cir.alloca !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>>, ["b", init, const] {alignment = 8 : i64} loc(#loc33)
4848
%1 = cir.alloca !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>>, ["__retval"] {alignment = 8 : i64} loc(#loc11)
4949
cir.store %arg0, %0 : !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>> loc(#loc14)
@@ -64,7 +64,7 @@ module @"/Users/henrichlauko/src/clangir/clang/test/CIR/CodeGen/dynamic-cast.cpp
6464
%11 = cir.load %1 : !cir.ptr<!cir.ptr<!rec_Derived>>, !cir.ptr<!rec_Derived> loc(#loc35)
6565
cir.return %11 : !cir.ptr<!rec_Derived> loc(#loc35)
6666
} loc(#loc32)
67-
cir.func dso_local @_Z20ptr_cast_to_completeP4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc21, #loc22])) -> !cir.ptr<!void> {inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone} {
67+
cir.func dso_local optnone @_Z20ptr_cast_to_completeP4Base(%arg0: !cir.ptr<!rec_Base> loc(fused[#loc21, #loc22])) -> !cir.ptr<!void> {inline = #cir.inline<no>, nothrow = #cir.nothrow} {
6868
%0 = cir.alloca !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>>, ["ptr", init] {alignment = 8 : i64} loc(#loc37)
6969
%1 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["__retval"] {alignment = 8 : i64} loc(#loc20)
7070
cir.store %arg0, %0 : !cir.ptr<!rec_Base>, !cir.ptr<!cir.ptr<!rec_Base>> loc(#loc23)

clang/test/CIR/CodeGen/optnone.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ int s0(int a, int b) {
1717
return x;
1818
}
1919

20-
// CIR-O0: #fn_attr = #cir<extra({inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone})>
21-
// CIR-O0: cir.func {{.*}} @_Z2s0ii(%arg0:{{.*}}, %arg1:{{.*}} -> {{.*}} extra(#fn_attr)
20+
// CIR-O0: #fn_attr = #cir<extra({inline = #cir.inline<no>, nothrow = #cir.nothrow})>
21+
// CIR-O0: cir.func {{.*}}optnone {{.*}} @_Z2s0ii(%arg0:{{.*}}, %arg1:{{.*}} -> {{.*}} extra(#fn_attr)
2222

23-
// CIR-O2-NOT: #fn_attr ={{.*}} optnone
23+
// CIR-O2-NOT: cir.func optnone
2424

2525
// LLVM-O0: define dso_local i32 @_Z2s0ii(i32 %0, i32 %1) #[[#ATTR:]]
2626
// LLVM-O0: attributes #[[#ATTR]] = { noinline nounwind optnone }

0 commit comments

Comments
 (0)