[SandboxIR][NFC] Move Function class to a separate file (#110526)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/SandboxIR/Module.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
|
||||
@@ -1227,59 +1227,6 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
class Function : public GlobalWithNodeAPI<Function, llvm::Function,
|
||||
GlobalObject, llvm::GlobalObject> {
|
||||
/// Helper for mapped_iterator.
|
||||
struct LLVMBBToBB {
|
||||
Context &Ctx;
|
||||
LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
|
||||
BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
|
||||
return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
|
||||
}
|
||||
};
|
||||
/// Use Context::createFunction() instead.
|
||||
Function(llvm::Function *F, sandboxir::Context &Ctx)
|
||||
: GlobalWithNodeAPI(ClassID::Function, F, Ctx) {}
|
||||
friend class Context; // For constructor.
|
||||
|
||||
public:
|
||||
/// For isa/dyn_cast.
|
||||
static bool classof(const sandboxir::Value *From) {
|
||||
return From->getSubclassID() == ClassID::Function;
|
||||
}
|
||||
|
||||
Module *getParent() {
|
||||
return Ctx.getModule(cast<llvm::Function>(Val)->getParent());
|
||||
}
|
||||
|
||||
Argument *getArg(unsigned Idx) const {
|
||||
llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
|
||||
return cast<Argument>(Ctx.getValue(Arg));
|
||||
}
|
||||
|
||||
size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
|
||||
bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
|
||||
|
||||
using iterator = mapped_iterator<llvm::Function::iterator, LLVMBBToBB>;
|
||||
iterator begin() const {
|
||||
LLVMBBToBB BBGetter(Ctx);
|
||||
return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
|
||||
}
|
||||
iterator end() const {
|
||||
LLVMBBToBB BBGetter(Ctx);
|
||||
return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
|
||||
}
|
||||
FunctionType *getFunctionType() const;
|
||||
|
||||
#ifndef NDEBUG
|
||||
void verify() const final {
|
||||
assert(isa<llvm::Function>(Val) && "Expected Function!");
|
||||
}
|
||||
void dumpNameAndArgs(raw_ostream &OS) const;
|
||||
void dumpOS(raw_ostream &OS) const final;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace llvm::sandboxir
|
||||
|
||||
#endif // LLVM_SANDBOXIR_CONSTANT_H
|
||||
|
||||
72
llvm/include/llvm/SandboxIR/Function.h
Normal file
72
llvm/include/llvm/SandboxIR/Function.h
Normal file
@@ -0,0 +1,72 @@
|
||||
//===- Function.h -----------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_SANDBOXIR_FUNCTION_H
|
||||
#define LLVM_SANDBOXIR_FUNCTION_H
|
||||
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
class Function : public GlobalWithNodeAPI<Function, llvm::Function,
|
||||
GlobalObject, llvm::GlobalObject> {
|
||||
/// Helper for mapped_iterator.
|
||||
struct LLVMBBToBB {
|
||||
Context &Ctx;
|
||||
LLVMBBToBB(Context &Ctx) : Ctx(Ctx) {}
|
||||
BasicBlock &operator()(llvm::BasicBlock &LLVMBB) const {
|
||||
return *cast<BasicBlock>(Ctx.getValue(&LLVMBB));
|
||||
}
|
||||
};
|
||||
/// Use Context::createFunction() instead.
|
||||
Function(llvm::Function *F, sandboxir::Context &Ctx)
|
||||
: GlobalWithNodeAPI(ClassID::Function, F, Ctx) {}
|
||||
friend class Context; // For constructor.
|
||||
|
||||
public:
|
||||
/// For isa/dyn_cast.
|
||||
static bool classof(const sandboxir::Value *From) {
|
||||
return From->getSubclassID() == ClassID::Function;
|
||||
}
|
||||
|
||||
Module *getParent() {
|
||||
return Ctx.getModule(cast<llvm::Function>(Val)->getParent());
|
||||
}
|
||||
|
||||
Argument *getArg(unsigned Idx) const {
|
||||
llvm::Argument *Arg = cast<llvm::Function>(Val)->getArg(Idx);
|
||||
return cast<Argument>(Ctx.getValue(Arg));
|
||||
}
|
||||
|
||||
size_t arg_size() const { return cast<llvm::Function>(Val)->arg_size(); }
|
||||
bool arg_empty() const { return cast<llvm::Function>(Val)->arg_empty(); }
|
||||
|
||||
using iterator = mapped_iterator<llvm::Function::iterator, LLVMBBToBB>;
|
||||
iterator begin() const {
|
||||
LLVMBBToBB BBGetter(Ctx);
|
||||
return iterator(cast<llvm::Function>(Val)->begin(), BBGetter);
|
||||
}
|
||||
iterator end() const {
|
||||
LLVMBBToBB BBGetter(Ctx);
|
||||
return iterator(cast<llvm::Function>(Val)->end(), BBGetter);
|
||||
}
|
||||
FunctionType *getFunctionType() const;
|
||||
|
||||
#ifndef NDEBUG
|
||||
void verify() const final {
|
||||
assert(isa<llvm::Function>(Val) && "Expected Function!");
|
||||
}
|
||||
void dumpNameAndArgs(raw_ostream &OS) const;
|
||||
void dumpOS(raw_ostream &OS) const final;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace llvm::sandboxir
|
||||
|
||||
#endif // LLVM_SANDBOXIR_FUNCTION_H
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "llvm/SandboxIR/BasicBlock.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
@@ -3,6 +3,7 @@ add_llvm_component_library(LLVMSandboxIR
|
||||
BasicBlock.cpp
|
||||
Constant.cpp
|
||||
Context.cpp
|
||||
Function.cpp
|
||||
Instruction.cpp
|
||||
Module.cpp
|
||||
Pass.cpp
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "llvm/SandboxIR/Argument.h"
|
||||
#include "llvm/SandboxIR/BasicBlock.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
@@ -467,44 +468,4 @@ GlobalValue *DSOLocalEquivalent::getGlobalValue() const {
|
||||
Ctx.getValue(cast<llvm::DSOLocalEquivalent>(Val)->getGlobalValue()));
|
||||
}
|
||||
|
||||
FunctionType *Function::getFunctionType() const {
|
||||
return cast<FunctionType>(
|
||||
Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void Function::dumpNameAndArgs(raw_ostream &OS) const {
|
||||
auto *F = cast<llvm::Function>(Val);
|
||||
OS << *F->getReturnType() << " @" << F->getName() << "(";
|
||||
interleave(
|
||||
F->args(),
|
||||
[this, &OS](const llvm::Argument &LLVMArg) {
|
||||
auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));
|
||||
if (SBArg == nullptr)
|
||||
OS << "NULL";
|
||||
else
|
||||
SBArg->printAsOperand(OS);
|
||||
},
|
||||
[&] { OS << ", "; });
|
||||
OS << ")";
|
||||
}
|
||||
|
||||
void Function::dumpOS(raw_ostream &OS) const {
|
||||
dumpNameAndArgs(OS);
|
||||
OS << " {\n";
|
||||
auto *LLVMF = cast<llvm::Function>(Val);
|
||||
interleave(
|
||||
*LLVMF,
|
||||
[this, &OS](const llvm::BasicBlock &LLVMBB) {
|
||||
auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));
|
||||
if (BB == nullptr)
|
||||
OS << "NULL";
|
||||
else
|
||||
OS << *BB;
|
||||
},
|
||||
[&OS] { OS << "\n"; });
|
||||
OS << "}\n";
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
} // namespace llvm::sandboxir
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/SandboxIR/Module.h"
|
||||
|
||||
|
||||
55
llvm/lib/SandboxIR/Function.cpp
Normal file
55
llvm/lib/SandboxIR/Function.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//===- Function.cpp - The Function class of Sandbox IR --------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
FunctionType *Function::getFunctionType() const {
|
||||
return cast<FunctionType>(
|
||||
Ctx.getType(cast<llvm::Function>(Val)->getFunctionType()));
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void Function::dumpNameAndArgs(raw_ostream &OS) const {
|
||||
auto *F = cast<llvm::Function>(Val);
|
||||
OS << *F->getReturnType() << " @" << F->getName() << "(";
|
||||
interleave(
|
||||
F->args(),
|
||||
[this, &OS](const llvm::Argument &LLVMArg) {
|
||||
auto *SBArg = cast_or_null<Argument>(Ctx.getValue(&LLVMArg));
|
||||
if (SBArg == nullptr)
|
||||
OS << "NULL";
|
||||
else
|
||||
SBArg->printAsOperand(OS);
|
||||
},
|
||||
[&] { OS << ", "; });
|
||||
OS << ")";
|
||||
}
|
||||
|
||||
void Function::dumpOS(raw_ostream &OS) const {
|
||||
dumpNameAndArgs(OS);
|
||||
OS << " {\n";
|
||||
auto *LLVMF = cast<llvm::Function>(Val);
|
||||
interleave(
|
||||
*LLVMF,
|
||||
[this, &OS](const llvm::BasicBlock &LLVMBB) {
|
||||
auto *BB = cast_or_null<BasicBlock>(Ctx.getValue(&LLVMBB));
|
||||
if (BB == nullptr)
|
||||
OS << "NULL";
|
||||
else
|
||||
OS << *BB;
|
||||
},
|
||||
[&OS] { OS << "\n"; });
|
||||
OS << "}\n";
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
} // namespace llvm::sandboxir
|
||||
@@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "llvm/SandboxIR/Module.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Value.h"
|
||||
|
||||
using namespace llvm::sandboxir;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/SandboxIR/Region.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
|
||||
namespace llvm::sandboxir {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
|
||||
using namespace llvm::sandboxir;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/PassManager.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include "llvm/SandboxIR/Region.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/BasicBlock.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/SandboxIR/Module.h"
|
||||
#include "llvm/SandboxIR/Utils.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Interval.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/SandboxIR/Constant.h"
|
||||
#include "llvm/SandboxIR/Context.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/SandboxIR/Function.h"
|
||||
#include "llvm/SandboxIR/Instruction.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
Reference in New Issue
Block a user