Index: src/IceConverter.cpp |
diff --git a/src/llvm2ice.cpp b/src/IceConverter.cpp |
similarity index 81% |
copy from src/llvm2ice.cpp |
copy to src/IceConverter.cpp |
index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..654d5e87532022dc27d5db8220de8a768c33de46 100644 |
--- a/src/llvm2ice.cpp |
+++ b/src/IceConverter.cpp |
@@ -1,4 +1,4 @@ |
-//===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// |
+//===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// |
// |
// The Subzero Code Generator |
// |
@@ -7,12 +7,12 @@ |
// |
//===----------------------------------------------------------------------===// |
// |
-// This file defines a driver that uses LLVM capabilities to parse a |
-// bitcode file and build the LLVM IR, and then convert the LLVM basic |
-// blocks, instructions, and operands into their Subzero equivalents. |
+// This file implements the LLVM to ICE converter. |
// |
//===----------------------------------------------------------------------===// |
+#include "IceConverter.h" |
+ |
#include "IceCfg.h" |
#include "IceCfgNode.h" |
#include "IceDefs.h" |
@@ -29,17 +29,13 @@ |
#include "llvm/IR/Instructions.h" |
#include "llvm/IR/LLVMContext.h" |
#include "llvm/IR/Module.h" |
-#include "llvm/IRReader/IRReader.h" |
-#include "llvm/Support/CommandLine.h" |
-#include "llvm/Support/ErrorHandling.h" |
-#include "llvm/Support/raw_os_ostream.h" |
-#include "llvm/Support/SourceMgr.h" |
-#include <fstream> |
#include <iostream> |
using namespace llvm; |
+namespace { |
+ |
// Debugging helper |
template <typename T> static std::string LLVMObjectAsString(const T *O) { |
std::string Dump; |
@@ -599,6 +595,8 @@ private: |
} |
} |
if (Call->getNumArgs() + 1 != I->NumTypes) { |
+ std::cerr << "Call->getNumArgs() " << (int)Call->getNumArgs() |
+ << " I->NumTypes " << (int)I->NumTypes << "\n"; |
report_fatal_error("Mismatched # of args."); |
} |
for (size_t i = 1; i < I->NumTypes; ++i) { |
@@ -618,113 +616,10 @@ private: |
std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
}; |
-static cl::list<Ice::VerboseItem> VerboseList( |
- "verbose", cl::CommaSeparated, |
- cl::desc("Verbose options (can be comma-separated):"), |
- cl::values( |
- clEnumValN(Ice::IceV_Instructions, "inst", "Print basic instructions"), |
- clEnumValN(Ice::IceV_Deleted, "del", "Include deleted instructions"), |
- clEnumValN(Ice::IceV_InstNumbers, "instnum", |
- "Print instruction numbers"), |
- clEnumValN(Ice::IceV_Preds, "pred", "Show predecessors"), |
- clEnumValN(Ice::IceV_Succs, "succ", "Show successors"), |
- clEnumValN(Ice::IceV_Liveness, "live", "Liveness information"), |
- clEnumValN(Ice::IceV_RegManager, "rmgr", "Register manager status"), |
- clEnumValN(Ice::IceV_RegOrigins, "orig", "Physical register origins"), |
- clEnumValN(Ice::IceV_LinearScan, "regalloc", "Linear scan details"), |
- clEnumValN(Ice::IceV_Frame, "frame", "Stack frame layout details"), |
- clEnumValN(Ice::IceV_Timing, "time", "Pass timing details"), |
- clEnumValN(Ice::IceV_All, "all", "Use all verbose options"), |
- clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd)); |
-static cl::opt<Ice::TargetArch> TargetArch( |
- "target", cl::desc("Target architecture:"), cl::init(Ice::Target_X8632), |
- cl::values( |
- clEnumValN(Ice::Target_X8632, "x8632", "x86-32"), |
- clEnumValN(Ice::Target_X8632, "x86-32", "x86-32 (same as x8632)"), |
- clEnumValN(Ice::Target_X8632, "x86_32", "x86-32 (same as x8632)"), |
- clEnumValN(Ice::Target_X8664, "x8664", "x86-64"), |
- clEnumValN(Ice::Target_X8664, "x86-64", "x86-64 (same as x8664)"), |
- clEnumValN(Ice::Target_X8664, "x86_64", "x86-64 (same as x8664)"), |
- clEnumValN(Ice::Target_ARM32, "arm", "arm32"), |
- clEnumValN(Ice::Target_ARM32, "arm32", "arm32 (same as arm)"), |
- clEnumValN(Ice::Target_ARM64, "arm64", "arm64"), clEnumValEnd)); |
-static cl::opt<Ice::OptLevel> |
-OptLevel(cl::desc("Optimization level"), cl::init(Ice::Opt_m1), |
- cl::value_desc("level"), |
- cl::values(clEnumValN(Ice::Opt_m1, "Om1", "-1"), |
- clEnumValN(Ice::Opt_m1, "O-1", "-1"), |
- clEnumValN(Ice::Opt_0, "O0", "0"), |
- clEnumValN(Ice::Opt_1, "O1", "1"), |
- clEnumValN(Ice::Opt_2, "O2", "2"), clEnumValEnd)); |
-static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"), |
- cl::init("-")); |
-static cl::opt<std::string> OutputFilename("o", |
- cl::desc("Override output filename"), |
- cl::init("-"), |
- cl::value_desc("filename")); |
-static cl::opt<std::string> LogFilename("log", cl::desc("Set log filename"), |
- cl::init("-"), |
- cl::value_desc("filename")); |
-static cl::opt<std::string> |
-TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"), |
- cl::init(""), cl::value_desc("prefix")); |
-static cl::opt<bool> |
-DisableInternal("external", |
- cl::desc("Disable 'internal' linkage type for testing")); |
-static cl::opt<bool> |
-DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); |
- |
-static cl::opt<bool> SubzeroTimingEnabled( |
- "timing", cl::desc("Enable breakdown timing of Subzero translation")); |
- |
-static cl::opt<NaClFileFormat> InputFileFormat( |
- "bitcode-format", cl::desc("Define format of input file:"), |
- cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), |
- clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), |
- clEnumValEnd), |
- cl::init(LLVMFormat)); |
- |
-int main(int argc, char **argv) { |
- int ExitStatus = 0; |
- |
- cl::ParseCommandLineOptions(argc, argv); |
- |
- // Parse the input LLVM IR file into a module. |
- SMDiagnostic Err; |
- Module *Mod; |
- |
- { |
- Ice::Timer T; |
- Mod = NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); |
- |
- if (SubzeroTimingEnabled) { |
- std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec() |
- << " sec\n"; |
- } |
- } |
- |
- if (!Mod) { |
- Err.print(argv[0], errs()); |
- return 1; |
- } |
- |
- Ice::VerboseMask VMask = Ice::IceV_None; |
- for (unsigned i = 0; i != VerboseList.size(); ++i) |
- VMask |= VerboseList[i]; |
+} |
- std::ofstream Ofs; |
- if (OutputFilename != "-") { |
- Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
- } |
- raw_os_ostream *Os = |
- new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
- Os->SetUnbuffered(); |
- std::ofstream Lfs; |
- if (LogFilename != "-") { |
- Lfs.open(LogFilename.c_str(), std::ofstream::out); |
- } |
- raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
- Ls->SetUnbuffered(); |
+int Ice::Converter::convertToIce(llvm::Module *Mod) { |
+ int ExitStatus = 0; |
// Ideally, Func would be declared inside the loop and its object |
// would be automatically deleted at the end of the loop iteration. |
@@ -735,12 +630,11 @@ int main(int argc, char **argv) { |
// object, change all Ice::Constant related functions to use |
// GlobalContext instead of Cfg, and then clean up this loop. |
OwningPtr<Ice::Cfg> Func; |
- Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
if (I->empty()) |
continue; |
- LLVM2ICEConverter FunctionConverter(&Ctx); |
+ LLVM2ICEConverter FunctionConverter(Ctx); |
Ice::Timer TConvert; |
Func.reset(FunctionConverter.convertFunction(I)); |