15 #define GEN_PASS_DEF_LLVMADDCOMDATS
16 #include "mlir/Dialect/LLVMIR/Transforms/Passes.h.inc"
24 const char *comdatName =
"__llvm_comdat";
25 mlir::LLVM::ComdatOp comdatOp =
26 symbolTable.
lookup<mlir::LLVM::ComdatOp>(comdatName);
28 PatternRewriter::InsertionGuard guard(builder);
31 builder.
create<mlir::LLVM::ComdatOp>(module.getLoc(), comdatName);
32 symbolTable.
insert(comdatOp);
35 PatternRewriter::InsertionGuard guard(builder);
37 auto selectorOp = builder.
create<mlir::LLVM::ComdatSelectorOp>(
38 comdatOp.getLoc(), op.getSymName(), mlir::LLVM::comdat::Comdat::Any);
45 struct AddComdatsPass :
public LLVM::impl::LLVMAddComdatsBase<AddComdatsPass> {
46 void runOnOperation()
override {
48 ModuleOp mod = getOperation();
50 std::unique_ptr<SymbolTable> symbolTable;
53 symbolTable = std::make_unique<SymbolTable>(mod);
56 for (
auto op : mod.getBody()->getOps<LLVM::LLVMFuncOp>()) {
57 if (op.getLinkage() == LLVM::Linkage::Linkonce ||
58 op.getLinkage() == LLVM::Linkage::LinkonceODR) {
static void addComdat(LLVM::LLVMFuncOp &op, OpBuilder &builder, SymbolTable &symbolTable, ModuleOp &module)
static MLIRContext * getContext(OpFoldResult val)
MLIRContext * getContext() const
static FlatSymbolRefAttr get(StringAttr value)
Construct a symbol reference for the given value name.
This class helps build Operations.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Operation * lookup(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists.
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...