Continue sketching out basic infrastructure, including an input and output

filename, and printing of trivial stuff.  There is no parser yet, so the
input file is ignored.

PiperOrigin-RevId: 201596916
This commit is contained in:
Chris Lattner 2018-06-21 15:22:42 -07:00 committed by jpienaar
parent 80a03c80a9
commit 5fc587ecf8
8 changed files with 235 additions and 44 deletions

View file

@ -203,27 +203,3 @@ Copyright 2019 The MLIR Authors.
limitations under the License.
==============================================================================
Copyrights and Licenses for Third Party Software Distributed with LLVM:
==============================================================================
The LLVM software contains code written by third parties. Such software will
have its own individual LICENSE.TXT file in the directory in which it appears.
This file will describe the copyrights, license, and restrictions which apply
to that code.
The disclaimer of warranty in the University of Illinois Open Source License
applies to all code in the LLVM Distribution, and nothing in any of the
other licenses gives permission to use the names of the LLVM Team or the
University of Illinois to endorse or promote products derived from this
Software.
The following pieces of software have additional or alternate copyrights,
licenses, and/or restrictions:
Program Directory
------- ---------
Google Test llvm/utils/unittest/googletest
OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex}
pyyaml tests llvm/test/YAMLParser/{*.data, LICENSE.TXT}
ARM contributions llvm/lib/Target/ARM/LICENSE.TXT
md5 contributions llvm/lib/Support/MD5.cpp llvm/include/llvm/Support/MD5.h

View file

@ -1,4 +1,4 @@
//===- Function.h - MLIR Function Class ------------------------*- llvm -*-===//
//===- Function.h - MLIR Function Class -------------------------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
@ -15,18 +15,27 @@
// limitations under the License.
// =============================================================================
//
// TODO
// Functions are the basic unit of composition in MLIR. There are three
// different kinds of functions: external functions, CFG functions, and ML
// functions.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_IR_FUNCTION_H
#define MLIR_IR_FUNCTION_H
namespace mlir {
class Function {
public:
explicit Function();
#include "mlir/Support/LLVM.h"
namespace mlir {
/// This is the base class for all of the MLIR function types
class Function {
std::string name;
// TODO: type and lots of other stuff.
public:
explicit Function(StringRef name);
void print(raw_ostream &os);
void dump();
};
} // end namespace mlir

View file

@ -0,0 +1,42 @@
//===- Module.h - MLIR Module Class -----------------------------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// Module is the top-level container for code in an MLIR program.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_IR_MODULE_H
#define MLIR_IR_MODULE_H
#include "mlir/IR/Function.h"
#include <vector>
namespace mlir {
class Module {
public:
explicit Module();
// FIXME: wrong representation and API.
std::vector<Function*> functionList;
void print(raw_ostream &os);
void dump();
};
} // end namespace mlir
#endif // MLIR_IR_FUNCTION_H

View file

@ -0,0 +1,90 @@
//===- LLVM.h - Import and forward declare core LLVM types ------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// This file forward declares and imports various common LLVM datatypes that
// MLIR wants to use unqualified.
//
// Note that most of these are forward declared and then imported into the MLIR
// namespace with using decls, rather than being #included. This is because we
// want clients to explicitly #include the files they need.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_SUPPORT_LLVM_H
#define MLIR_SUPPORT_LLVM_H
// We include these two headers because they cannot be practically forward
// declared, and are effectively language features.
#include "llvm/Support/Casting.h"
#include "llvm/ADT/None.h"
// Forward declarations.
namespace llvm {
// Containers.
class StringRef;
class StringLiteral;
class Twine;
template <typename T> class SmallPtrSetImpl;
template <typename T, unsigned N> class SmallPtrSet;
template <typename T> class SmallVectorImpl;
template <typename T, unsigned N> class SmallVector;
template <unsigned N> class SmallString;
template<typename T> class ArrayRef;
template<typename T> class MutableArrayRef;
template<typename T> class TinyPtrVector;
template<typename T> class Optional;
template <typename PT1, typename PT2> class PointerUnion;
// Other common classes.
class raw_ostream;
class APInt;
class APFloat;
} // end namespace llvm
namespace mlir {
// Casting operators.
using llvm::isa;
using llvm::cast;
using llvm::dyn_cast;
using llvm::dyn_cast_or_null;
using llvm::cast_or_null;
// Containers.
using llvm::None;
using llvm::Optional;
using llvm::SmallPtrSetImpl;
using llvm::SmallPtrSet;
using llvm::SmallString;
using llvm::StringRef;
using llvm::StringLiteral;
using llvm::Twine;
using llvm::SmallVectorImpl;
using llvm::SmallVector;
using llvm::ArrayRef;
using llvm::MutableArrayRef;
using llvm::TinyPtrVector;
using llvm::PointerUnion;
// Other common classes.
using llvm::raw_ostream;
using llvm::APInt;
using llvm::APFloat;
using llvm::NoneType;
} // end namespace swift
#endif // MLIR_SUPPORT_LLVM_H

View file

@ -14,14 +14,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// TODO
//
//===----------------------------------------------------------------------===//
#include "mlir/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
Function::Function() {
Function::Function(StringRef name) : name(name.str()) {
}
void Function::print(raw_ostream &os) {
os << "extfunc @" << name << "()\n";
}
void Function::dump() {
print(llvm::errs());
}

34
mlir/lib/IR/Module.cpp Normal file
View file

@ -0,0 +1,34 @@
//===- Module.cpp - MLIR Module Class -------------------------------===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
#include "mlir/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
Module::Module() {
}
void Module::print(raw_ostream &os) {
for (auto *fn : functionList)
fn->print(os);
}
void Module::dump() {
print(llvm::errs());
}

View file

@ -1,9 +1,15 @@
// TODO(andydavis) Resolve relative path issue w.r.t invoking mlir-opt in RUN
// statements (perhaps through using lit config substitutions).
//
// RUN: %S/../../mlir-opt --help | FileCheck %s
// RUN: %S/../../mlir-opt --help | FileCheck --check-prefix=CHECKHELP %s
// RUN: %S/../../mlir-opt %s -o - | FileCheck %s
//
// CHECK: OVERVIEW: MLIR modular optimizer driver
// CHECKHELP: OVERVIEW: MLIR modular optimizer driver
extfunc @test()
// Right now the input is completely ignored.
extfunc @foo()
extfunc @bar()
// CHECK: extfunc @foo()
// CHECK: extfunc @bar()

View file

@ -21,18 +21,48 @@
//
//===----------------------------------------------------------------------===//
#include "mlir/IR/Function.h"
#include "mlir/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"
using namespace mlir;
using namespace llvm;
static cl::opt<std::string>
inputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
static cl::opt<std::string>
outputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
cl::init("-"));
/// Open the specified output file and return it, exiting if there is any I/O or
/// other errors.
static std::unique_ptr<ToolOutputFile> getOutputStream() {
std::error_code error;
auto result = make_unique<ToolOutputFile>(outputFilename, error,
sys::fs::F_None);
if (error) {
llvm::errs() << error.message() << '\n';
exit(1);
}
return result;
}
int main(int argc, char **argv) {
llvm::InitLLVM x(argc, argv);
InitLLVM x(argc, argv);
llvm::cl::ParseCommandLineOptions(argc, argv,
"MLIR modular optimizer driver\n");
cl::ParseCommandLineOptions(argc, argv, "MLIR modular optimizer driver\n");
// Instantiate an IR object.
Function f;
(void)f;
Module m;
m.functionList.push_back(new Function("foo"));
m.functionList.push_back(new Function("bar"));
// Print the output.
auto output = getOutputStream();
m.print(output->os());
output->keep();
}