File tree Expand file tree Collapse file tree 6 files changed +43
-0
lines changed
include/clang/CIR/Dialect/IR Expand file tree Collapse file tree 6 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ def CIR_Dialect : Dialect {
40
40
static llvm::StringRef getCalleeAttrName() { return "callee"; }
41
41
static llvm::StringRef getNoThrowAttrName() { return "nothrow"; }
42
42
static llvm::StringRef getSideEffectAttrName() { return "side_effect"; }
43
+ static llvm::StringRef getModuleLevelAsmAttrName() { return "cir.module_asm"; }
43
44
44
45
void registerAttributes();
45
46
void registerTypes();
Original file line number Diff line number Diff line change @@ -1365,6 +1365,21 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
1365
1365
assert (!cir::MissingFeatures::generateDebugInfo ());
1366
1366
assert (!cir::MissingFeatures::cxxRecordStaticMembers ());
1367
1367
break ;
1368
+
1369
+ case Decl::FileScopeAsm:
1370
+ // File-scope asm is ignored during device-side CUDA compilation.
1371
+ if (langOpts.CUDA && langOpts.CUDAIsDevice )
1372
+ break ;
1373
+ // File-scope asm is ignored during device-side OpenMP compilation.
1374
+ if (langOpts.OpenMPIsTargetDevice )
1375
+ break ;
1376
+ // File-scope asm is ignored during device-side SYCL compilation.
1377
+ if (langOpts.SYCLIsDevice )
1378
+ break ;
1379
+ auto *file_asm = cast<FileScopeAsmDecl>(decl);
1380
+ std::string line = file_asm->getAsmString ();
1381
+ globalScopeAsm.push_back (builder.getStringAttr (line));
1382
+ break ;
1368
1383
}
1369
1384
}
1370
1385
@@ -1978,6 +1993,9 @@ void CIRGenModule::release() {
1978
1993
emitDeferred ();
1979
1994
applyReplacements ();
1980
1995
1996
+ theModule->setAttr (cir::CIRDialect::getModuleLevelAsmAttrName (),
1997
+ builder.getArrayAttr (globalScopeAsm));
1998
+
1981
1999
// There's a lot of code that is not implemented yet.
1982
2000
assert (!cir::MissingFeatures::cgmRelease ());
1983
2001
}
Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ class CIRGenModule : public CIRGenTypeCache {
90
90
// / for FunctionDecls's.
91
91
CIRGenFunction *curCGF = nullptr ;
92
92
93
+ llvm::SmallVector<mlir::Attribute> globalScopeAsm;
94
+
93
95
public:
94
96
mlir::ModuleOp getModule () const { return theModule; }
95
97
CIRGenBuilderTy &getBuilder () { return builder; }
Original file line number Diff line number Diff line change @@ -2143,6 +2143,11 @@ void ConvertCIRToLLVMPass::processCIRAttrs(mlir::ModuleOp module) {
2143
2143
module ->getAttr (cir::CIRDialect::getTripleAttrName ()))
2144
2144
module ->setAttr (mlir::LLVM::LLVMDialect::getTargetTripleAttrName (),
2145
2145
tripleAttr);
2146
+
2147
+ if (mlir::Attribute asmAttr =
2148
+ module ->getAttr (cir::CIRDialect::getModuleLevelAsmAttrName ()))
2149
+ module ->setAttr (mlir::LLVM::LLVMDialect::getModuleLevelAsmAttrName (),
2150
+ asmAttr);
2146
2151
}
2147
2152
2148
2153
void ConvertCIRToLLVMPass::runOnOperation () {
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o %t.cir
2
+ // RUN: FileCheck --input-file=%t.cir %s
3
+
4
+ // CHECK: cir.module_asm = [".globl bar", ".globl foo"]
5
+ __asm (".globl bar" );
6
+ __asm (".globl foo" );
Original file line number Diff line number Diff line change
1
+ // RUN: cir-opt %s -cir-to-llvm -o %t.cir
2
+ // RUN: FileCheck %s --input-file=%t.cir
3
+
4
+ // RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s
5
+ // RUN: FileCheck -check-prefix=LLVM --input-file=%t.ll %s
6
+
7
+ // CHECK: llvm.module_asm = [".globl bar", ".globl foo"]
8
+ // LLVM: module asm ".globl bar"
9
+ // LLVM: module asm ".globl foo"
10
+ module attributes {cir.module_asm = [".globl bar", ".globl foo"]} {
11
+ }
You can’t perform that action at this time.
0 commit comments