Skip to content

Commit

Permalink
[CIR] Merge two copies of CIRGenAction.h (#1085)
Browse files Browse the repository at this point in the history
We have both clang/include/clang/CIRFrontendAction/CIRGenAction.h and
clang/include/clang/cir/FrontendAction/CIRGenAction.h, which is a
historical artifact. The latter is what's being upstreamed, so merge the
former into it to avoid any confusion.
  • Loading branch information
smeenai authored Nov 8, 2024
1 parent 0c77b27 commit 2fc3593
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 197 deletions.
143 changes: 136 additions & 7 deletions clang/include/clang/CIR/FrontendAction/CIRGenAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,181 @@
#ifndef LLVM_CLANG_CIR_CIRGENACTION_H
#define LLVM_CLANG_CIR_CIRGENACTION_H

#include "clang/CodeGen/CodeGenAction.h"
#include "clang/Frontend/FrontendAction.h"
#include <memory>

#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/OwningOpRef.h"
namespace llvm {
class LLVMIRContext;
class Module;
} // namespace llvm

namespace mlir {
class MLIRContext;
class ModuleOp;
template <typename T> class OwningOpRef;
} // namespace mlir

namespace cir {
class CIRGenConsumer;
class CIRGenerator;

class CIRGenAction : public clang::ASTFrontendAction {
public:
enum class OutputType {
EmitAssembly,
EmitCIR,
EmitCIRFlat,
EmitLLVM,
EmitBC,
EmitMLIR,
EmitObj,
None
};

private:
friend class CIRGenConsumer;

mlir::OwningOpRef<mlir::ModuleOp> MLIRMod;
// TODO: this is redundant but just using the OwningModuleRef requires more of
// clang against MLIR. Hide this somewhere else.
std::unique_ptr<mlir::OwningOpRef<mlir::ModuleOp>> mlirModule;
std::unique_ptr<llvm::Module> llvmModule;

mlir::MLIRContext *MLIRCtx;
mlir::MLIRContext *mlirContext;

mlir::OwningOpRef<mlir::ModuleOp> loadModule(llvm::MemoryBufferRef mbRef);

protected:
CIRGenAction(OutputType Action, mlir::MLIRContext *MLIRCtx = nullptr);
CIRGenAction(OutputType action, mlir::MLIRContext *_MLIRContext = nullptr);

std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &CI,
llvm::StringRef InFile) override;

void ExecuteAction() override;

void EndSourceFileAction() override;

public:
~CIRGenAction() override;

OutputType Action;
virtual bool hasCIRSupport() const override { return true; }

CIRGenConsumer *cgConsumer;
OutputType action;
};

class EmitCIRAction : public CIRGenAction {
virtual void anchor();

public:
EmitCIRAction(mlir::MLIRContext *MLIRCtx = nullptr);
EmitCIRAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitCIRFlatAction : public CIRGenAction {
virtual void anchor();

public:
EmitCIRFlatAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitCIROnlyAction : public CIRGenAction {
virtual void anchor();

public:
EmitCIROnlyAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitMLIRAction : public CIRGenAction {
virtual void anchor();

public:
EmitMLIRAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitLLVMAction : public CIRGenAction {
virtual void anchor();

public:
EmitLLVMAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitBCAction : public CIRGenAction {
virtual void anchor();

public:
EmitBCAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitAssemblyAction : public CIRGenAction {
virtual void anchor();

public:
EmitAssemblyAction(mlir::MLIRContext *mlirCtx = nullptr);
};

class EmitObjAction : public CIRGenAction {
virtual void anchor();

public:
EmitObjAction(mlir::MLIRContext *mlirCtx = nullptr);
};

// Used for -fclangir-analysis-only: use CIR analysis but still use original
// LLVM codegen path
class AnalysisOnlyActionBase : public clang::CodeGenAction {
virtual void anchor();

protected:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &CI,
llvm::StringRef InFile) override;

AnalysisOnlyActionBase(unsigned _Act,
llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitAssemblyAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitBCAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitLLVMAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitLLVMOnlyAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitCodeGenOnlyAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
};

class AnalysisOnlyAndEmitObjAction : public AnalysisOnlyActionBase {
virtual void anchor() override;

public:
AnalysisOnlyAndEmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
};
} // namespace cir

#endif
188 changes: 0 additions & 188 deletions clang/include/clang/CIRFrontendAction/CIRGenAction.h

This file was deleted.

2 changes: 1 addition & 1 deletion clang/lib/CIR/FrontendAction/CIRGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "clang/CIRFrontendAction/CIRGenAction.h"
#include "clang/CIR/FrontendAction/CIRGenAction.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/BuiltinOps.h"
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/Pass/PassManager.h"
#include "clang/CIR/Dialect/Passes.h"
#include "clang/CIRFrontendAction/CIRGenAction.h"
#include "clang/CIR/FrontendAction/CIRGenAction.h"
#endif

using namespace clang;
Expand Down

0 comments on commit 2fc3593

Please sign in to comment.