Skip to content

Commit f969d2d

Browse files
committed
Addressed some review feedback
- Various formatting changes - Changed file header comments - Changed include guards - Added global linkage to LLVM lowering
1 parent a6224ab commit f969d2d

File tree

9 files changed

+67
-56
lines changed

9 files changed

+67
-56
lines changed

clang/include/clang/CIR/Dialect/IR/CIROpsEnums.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- CIROpsEnumsDialect.h - MLIR Dialect for CIR ----------------------*- C++
1+
//===----------------------------------------------------------------------===//
22
//-*-===//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,12 +7,12 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This file declares the Target dialect for CIR in MLIR.
10+
// This file declares the CIR enumerations.
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef MLIR_DIALECT_CIR_CIROPSENUMS_H_
15-
#define MLIR_DIALECT_CIR_CIROPSENUMS_H_
14+
#ifndef CLANG_CIR_DIALECT_IR_CIROPSENUMS_H
15+
#define CLANG_CIR_DIALECT_IR_CIROPSENUMS_H
1616

1717
#include "mlir/IR/BuiltinAttributes.h"
1818
#include "clang/CIR/Dialect/IR/CIROpsEnums.h.inc"
@@ -116,4 +116,4 @@ LLVM_ATTRIBUTE_UNUSED static bool isValidLinkage(GlobalLinkageKind gl) {
116116

117117
} // namespace cir
118118

119-
#endif // MLIR_DIALECT_CIR_CIROPSENUMS_H_
119+
#endif // CLANG_CIR_DIALECT_IR_CIROPSENUMS_H
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- CIROpInterfaces.h - CIR Op Interfaces --------------------*- C++ -*-===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_INTERFACES_CIR_OP_H_
10-
#define MLIR_INTERFACES_CIR_OP_H_
9+
#ifndef CLANG_CIR_INTERFACES_CIR_OP_H
10+
#define CLANG_CIR_INTERFACES_CIR_OP_H
1111

1212
#include "mlir/IR/Attributes.h"
1313
#include "mlir/IR/Operation.h"
@@ -19,11 +19,7 @@
1919
#include "clang/AST/Mangle.h"
2020
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
2121

22-
namespace cir {} // namespace cir
23-
2422
/// Include the generated interface declarations.
2523
#include "clang/CIR/Interfaces/CIROpInterfaces.h.inc"
2624

27-
namespace cir {} // namespace cir
28-
29-
#endif // MLIR_INTERFACES_CIR_OP_H_
25+
#endif // CLANG_CIR_INTERFACES_CIR_OP_H

clang/include/clang/CIR/Interfaces/CIROpInterfaces.td

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,40 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_CIR_OP_INTERFACES
10-
#define MLIR_CIR_OP_INTERFACES
9+
#ifndef CLANG_CIR_INTERFACES_CIROPINTERFACES_TD
10+
#define CLANG_CIR_INTERFACES_CIROPINTERFACES_TD
1111

1212
include "mlir/IR/OpBase.td"
1313

1414
let cppNamespace = "::cir" in {
15-
def CIRGlobalValueInterface
16-
: OpInterface<"CIRGlobalValueInterface"> {
15+
def CIRGlobalValueInterface : OpInterface<"CIRGlobalValueInterface"> {
1716

18-
let methods = [
19-
InterfaceMethod<"",
20-
"bool", "hasAvailableExternallyLinkage", (ins), [{}],
21-
/*defaultImplementation=*/[{ return false; }]
22-
>,
23-
InterfaceMethod<"",
24-
"bool", "hasLocalLinkage", (ins), [{}],
25-
/*defaultImplementation=*/[{
17+
let methods =
18+
[InterfaceMethod<"", "bool", "hasAvailableExternallyLinkage", (ins),
19+
[{}],
20+
/*defaultImplementation=*/[{ return false; }]>,
21+
InterfaceMethod<"", "bool", "hasLocalLinkage", (ins), [{}],
22+
/*defaultImplementation=*/[{
2623
return cir::isLocalLinkage($_op.getLinkage());
27-
}]
28-
>,
29-
InterfaceMethod<"",
30-
"bool", "hasExternalWeakLinkage", (ins), [{}],
31-
/*defaultImplementation=*/[{
24+
}]>,
25+
InterfaceMethod<"", "bool", "hasExternalWeakLinkage", (ins), [{}],
26+
/*defaultImplementation=*/[{
3227
return cir::isExternalWeakLinkage($_op.getLinkage());
33-
}]
34-
>,
35-
InterfaceMethod<"",
36-
"bool", "isExternalLinkage", (ins), [{}],
37-
/*defaultImplementation=*/[{
28+
}]>,
29+
InterfaceMethod<"", "bool", "isExternalLinkage", (ins), [{}],
30+
/*defaultImplementation=*/[{
3831
return cir::isExternalLinkage($_op.getLinkage());
39-
}]
40-
>,
41-
InterfaceMethod<"",
42-
"bool", "isDeclarationForLinker", (ins), [{}],
43-
/*defaultImplementation=*/[{
32+
}]>,
33+
InterfaceMethod<"", "bool", "isDeclarationForLinker", (ins), [{}],
34+
/*defaultImplementation=*/[{
4435
if ($_op.hasAvailableExternallyLinkage())
4536
return true;
4637
return $_op.isDeclaration();
47-
}]
48-
>,
49-
InterfaceMethod<"",
50-
"void", "setDSOLocal", (ins "bool":$val), [{}],
51-
/*defaultImplementation=*/[{
38+
}]>,
39+
InterfaceMethod<"", "void", "setDSOLocal", (ins "bool":$val), [{}],
40+
/*defaultImplementation=*/[{
5241
$_op.setDsolocal(val);
53-
}]
54-
>,
42+
}]>,
5543
];
5644
let extraClassDeclaration = [{
5745
bool canBenefitFromLocalAlias();
@@ -60,4 +48,4 @@ let cppNamespace = "::cir" in {
6048

6149
} // namespace cir
6250

63-
#endif // MLIR_CIR_OP_INTERFACES
51+
#endif // CLANG_CIR_INTERFACES_CIROPINTERFACES_TD

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct MissingFeatures {
3838
static bool opGlobalThreadLocal() { return false; }
3939
static bool opGlobalConstant() { return false; }
4040
static bool opGlobalAlignment() { return false; }
41-
static bool opGlobalLinkage() { return false; }
4241

4342
static bool supportIFuncAttr() { return false; }
4443
static bool supportVisibility() { return false; }

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
185185
// Set CIR linkage and DLL storage class.
186186
varOp.setLinkage(linkage);
187187

188-
if (linkage == cir::GlobalLinkageKind::CommonLinkage) {
188+
if (linkage == cir::GlobalLinkageKind::CommonLinkage)
189189
errorNYI(initExpr->getSourceRange(), "common linkage");
190-
}
191190

192191
theModule.push_back(varOp);
193192
} else {

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ using namespace llvm;
3737
namespace cir {
3838
namespace direct {
3939

40+
mlir::LLVM::Linkage convertLinkage(cir::GlobalLinkageKind linkage) {
41+
using CIR = cir::GlobalLinkageKind;
42+
using LLVM = mlir::LLVM::Linkage;
43+
44+
switch (linkage) {
45+
case CIR::AvailableExternallyLinkage:
46+
return LLVM::AvailableExternally;
47+
case CIR::CommonLinkage:
48+
return LLVM::Common;
49+
case CIR::ExternalLinkage:
50+
return LLVM::External;
51+
case CIR::ExternalWeakLinkage:
52+
return LLVM::ExternWeak;
53+
case CIR::InternalLinkage:
54+
return LLVM::Internal;
55+
case CIR::LinkOnceAnyLinkage:
56+
return LLVM::Linkonce;
57+
case CIR::LinkOnceODRLinkage:
58+
return LLVM::LinkonceODR;
59+
case CIR::PrivateLinkage:
60+
return LLVM::Private;
61+
case CIR::WeakAnyLinkage:
62+
return LLVM::Weak;
63+
case CIR::WeakODRLinkage:
64+
return LLVM::WeakODR;
65+
};
66+
}
67+
4068
class CIRAttrToValue {
4169
public:
4270
CIRAttrToValue(mlir::Operation *parentOp,
@@ -160,8 +188,7 @@ void CIRToLLVMGlobalOpLowering::setupRegionInitializedLLVMGlobalOp(
160188
const bool isThreadLocal = false;
161189
assert(!cir::MissingFeatures::opGlobalAlignment());
162190
const uint64_t alignment = 0;
163-
assert(!cir::MissingFeatures::opGlobalLinkage());
164-
const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
191+
const mlir::LLVM::Linkage linkage = convertLinkage(op.getLinkage());
165192
const StringRef symbol = op.getSymName();
166193

167194
SmallVector<mlir::NamedAttribute> attributes;
@@ -215,8 +242,7 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
215242
const bool isThreadLocal = false;
216243
assert(!cir::MissingFeatures::opGlobalAlignment());
217244
const uint64_t alignment = 0;
218-
assert(!cir::MissingFeatures::opGlobalLinkage());
219-
const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
245+
const mlir::LLVM::Linkage linkage = convertLinkage(op.getLinkage());
220246
const StringRef symbol = op.getSymName();
221247
SmallVector<mlir::NamedAttribute> attributes;
222248

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
#ifndef CLANG_CIR_LOWERTOLLVM_H
1313
#define CLANG_CIR_LOWERTOLLVM_H
1414

15+
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
1516
#include "mlir/Transforms/DialectConversion.h"
1617
#include "clang/CIR/Dialect/IR/CIRDialect.h"
1718

1819
namespace cir {
1920

2021
namespace direct {
2122

23+
mlir::LLVM::Linkage convertLinkage(cir::GlobalLinkageKind linkage);
24+
2225
class CIRToLLVMGlobalOpLowering
2326
: public mlir::OpConversionPattern<cir::GlobalOp> {
2427
const mlir::DataLayout &dataLayout;
File renamed without changes.

clang/test/CIR/global-var-simple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsigned _BitInt(48) ub48;
5959
// CHECK: cir.global external @ub48 : !cir.int<u, 48>
6060

6161
bool boolfalse = false;
62-
// CHECK: cir.global @boolfalse = #false
62+
// CHECK: cir.global external @boolfalse = #false
6363

6464
_Float16 f16;
6565
// CHECK: cir.global external @f16 : !cir.f16

0 commit comments

Comments
 (0)