Skip to content

Commit f51ff0d

Browse files
ivanradanovwsmoses
andauthored
Prefix ABI (#197)
* Prefix ABI * Fix format Co-authored-by: William S. Moses <[email protected]>
1 parent 93d5a1e commit f51ff0d

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

tools/mlir-clang/Lib/clang-mlir.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ static cl::opt<bool>
5757
static cl::opt<bool> memRefABI("memref-abi", cl::init(true),
5858
cl::desc("Use memrefs when possible"));
5959

60+
cl::opt<std::string> PrefixABI("prefix-abi", cl::init(""),
61+
cl::desc("Prefix for emitted symbols"));
62+
6063
static cl::opt<bool>
6164
CombinedStructABI("struct-abi", cl::init(true),
6265
cl::desc("Use literal LLVM ABI for structs"));
@@ -3955,6 +3958,8 @@ MLIRASTConsumer::GetOrCreateLLVMFunction(const FunctionDecl *FD) {
39553958
else
39563959
name = CGM.getMangledName(FD).str();
39573960

3961+
name = (PrefixABI + name);
3962+
39583963
if (llvmFunctions.find(name) != llvmFunctions.end()) {
39593964
return llvmFunctions[name];
39603965
}
@@ -4025,6 +4030,8 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD,
40254030
std::string prefix) {
40264031
std::string name = prefix + CGM.getMangledName(FD).str();
40274032

4033+
name = (PrefixABI + name);
4034+
40284035
if (llvmGlobals.find(name) != llvmGlobals.end()) {
40294036
return llvmGlobals[name];
40304037
}
@@ -4163,6 +4170,8 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix,
41634170
bool tryInit) {
41644171
std::string name = prefix + CGM.getMangledName(FD).str();
41654172

4173+
name = (PrefixABI + name);
4174+
41664175
if (globals.find(name) != globals.end()) {
41674176
return globals[name];
41684177
}
@@ -4321,6 +4330,8 @@ mlir::FuncOp MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD) {
43214330
else
43224331
name = CGM.getMangledName(FD).str();
43234332

4333+
name = (PrefixABI + name);
4334+
43244335
assert(name != "free");
43254336

43264337
llvm::GlobalValue::LinkageTypes LV;

tools/mlir-clang/Lib/clang-mlir.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
#ifndef CLANG_MLIR_H
1010
#define CLANG_MLIR_H
1111

12-
#include "clang/AST/ASTConsumer.h"
13-
#include "clang/AST/StmtVisitor.h"
14-
#include "clang/Lex/HeaderSearch.h"
15-
#include "clang/Lex/HeaderSearchOptions.h"
16-
#include "clang/Lex/Preprocessor.h"
17-
#include "clang/Lex/PreprocessorOptions.h"
18-
1912
#include "AffineUtils.h"
2013
#include "ValueCategory.h"
2114
#include "mlir/Dialect/Affine/IR/AffineOps.h"
@@ -33,7 +26,14 @@
3326
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
3427
#include "polygeist/Ops.h"
3528
#include "pragmaHandler.h"
29+
#include "clang/AST/ASTConsumer.h"
30+
#include "clang/AST/StmtVisitor.h"
31+
#include "clang/Lex/HeaderSearch.h"
32+
#include "clang/Lex/HeaderSearchOptions.h"
33+
#include "clang/Lex/Preprocessor.h"
34+
#include "clang/Lex/PreprocessorOptions.h"
3635
#include "llvm/IR/DerivedTypes.h"
36+
#include "llvm/Support/CommandLine.h"
3737

3838
#include "clang/../../lib/CodeGen/CGRecordLayout.h"
3939
#include "clang/../../lib/CodeGen/CodeGenModule.h"
@@ -42,6 +42,8 @@
4242
using namespace clang;
4343
using namespace mlir;
4444

45+
extern llvm::cl::opt<std::string> PrefixABI;
46+
4547
struct LoopContext {
4648
mlir::Value keepRunning;
4749
mlir::Value noBreak;

0 commit comments

Comments
 (0)