support llvm-9 or 10 but the generated code is slow

update-fork
MITSUNARI Shigeo 5 years ago
parent 74342272a3
commit 3b8caf72bc
  1. 6
      Makefile
  2. 9
      src/gen.cpp
  3. 25
      src/llvm_gen.hpp

@ -68,13 +68,13 @@ all: $(MCL_LIB) $(MCL_SLIB) $(BN256_LIB) $(BN256_SLIB) $(BN384_LIB) $(BN384_SLIB
#LLVM_VER=-3.8 #LLVM_VER=-3.8
LLVM_LLC=llc$(LLVM_VER) LLVM_LLC=llc$(LLVM_VER)
LLVM_OPT=opt$(LLVM_VER) LLVM_OPT=opt$(LLVM_VER)
LLVM_OPT_VERSION=$(shell $(LLVM_OPT) --version 2>/dev/null | awk '/version/ {print $$3}') LLVM_OPT_VERSION=$(shell $(LLVM_OPT) --version 2>/dev/null | awk '/version/ { split($$3,a,"."); print a[1]}')
GEN_EXE=src/gen GEN_EXE=src/gen
GEN_EXE_OPT=-u $(BIT) GEN_EXE_OPT=-u $(BIT)
# incompatibility between llvm 3.4 and the later version # incompatibility between llvm 3.4 and the later version
ifneq ($(LLVM_OPT_VERSION),) ifneq ($(LLVM_OPT_VERSION),)
ifeq ($(shell expr $(LLVM_OPT_VERSION) \< 3.5.0),1) ifeq ($(shell expr $(LLVM_OPT_VERSION) \>= 9),1)
GEN_EXE_OPT+=-old GEN_EXE_OPT+=-ver 0x90
endif endif
endif endif
ifeq ($(OS),mac) ifeq ($(OS),mac)

@ -982,13 +982,13 @@ int main(int argc, char *argv[])
try try
{ {
uint32_t unit; uint32_t unit;
bool oldLLVM; int llvmVer;
bool wasm; bool wasm;
std::string suf; std::string suf;
std::string privateFile; std::string privateFile;
cybozu::Option opt; cybozu::Option opt;
opt.appendOpt(&unit, uint32_t(sizeof(void*)) * 8, "u", ": unit"); opt.appendOpt(&unit, uint32_t(sizeof(void*)) * 8, "u", ": unit");
opt.appendBoolOpt(&oldLLVM, "old", ": old LLVM(before 3.8)"); opt.appendOpt(&llvmVer, 0x70, "ver", ": llvm version");
opt.appendBoolOpt(&wasm, "wasm", ": for wasm"); opt.appendBoolOpt(&wasm, "wasm", ": for wasm");
opt.appendOpt(&suf, "", "s", ": suffix of function name"); opt.appendOpt(&suf, "", "s", ": suffix of function name");
opt.appendOpt(&privateFile, "", "f", ": private function list file"); opt.appendOpt(&privateFile, "", "f", ": private function list file");
@ -1006,9 +1006,8 @@ int main(int argc, char *argv[])
} }
} }
Code c; Code c;
if (oldLLVM) { fprintf(stderr, "llvmVer=0x%02x\n", llvmVer);
c.setOldLLVM(); c.setLlvmVer(llvmVer);
}
c.wasm = wasm; c.wasm = wasm;
c.setUnit(unit); c.setUnit(unit);
uint32_t maxBitSize = MCL_MAX_BIT_SIZE; uint32_t maxBitSize = MCL_MAX_BIT_SIZE;

@ -46,16 +46,14 @@ struct File {
template<size_t dummy=0> template<size_t dummy=0>
struct Param { struct Param {
static File f; static File f;
static int llvmVer;
}; };
template<size_t dummy> template<size_t dummy>
File Param<dummy>::f; File Param<dummy>::f;
bool isOldLLVM = false;
} // mcl::impl } // mcl::impl
inline bool isOldLLVM() { return impl::isOldLLVM; }
struct Generator { struct Generator {
static const uint8_t None = 0; static const uint8_t None = 0;
@ -63,7 +61,14 @@ struct Generator {
static const uint8_t Imm = 2; static const uint8_t Imm = 2;
static const uint8_t Ptr = 1 << 7; static const uint8_t Ptr = 1 << 7;
static const uint8_t IntPtr = Int | Ptr; static const uint8_t IntPtr = Int | Ptr;
void setOldLLVM() { impl::isOldLLVM = true; } int llvmVer;
void setOldLLVM() { llvmVer = 0x37; }
static const int V8 = 0x90;
bool isNewer(int ver) const
{
return llvmVer > ver;
}
void setLlvmVer(int ver) { llvmVer = ver; }
struct Type { struct Type {
uint8_t type; uint8_t type;
bool isPtr; bool isPtr;
@ -474,9 +479,11 @@ inline Generator::Eval Generator::getelementptr(const Generator::Operand& p, con
Eval e; Eval e;
e.op = p; e.op = p;
e.s = "getelementptr "; e.s = "getelementptr ";
if (!isOldLLVM()) { const std::string bit = cybozu::itoa(p.bit);
e.s += "i" + cybozu::itoa(p.bit) + ", "; if (isNewer(V8)) {
e.s += " inbounds " + bit + ", ";
} }
e.s += "i" + bit + ", ";
e.s += p.toStr() + ", " + i.toStr(); e.s += p.toStr() + ", " + i.toStr();
return e; return e;
} }
@ -493,9 +500,11 @@ inline Generator::Eval Generator::load(const Generator::Operand& p)
e.op = p; e.op = p;
e.op.type.isPtr = false; e.op.type.isPtr = false;
e.s = "load "; e.s = "load ";
if (!isOldLLVM()) { const std::string bit = cybozu::itoa(p.bit);
e.s += "i" + cybozu::itoa(p.bit) + ", "; if (isNewer(V8)) {
e.s += "i" + bit + ", ";
} }
e.s += "i" + bit + ", ";
e.s += p.toStr(); e.s += p.toStr();
return e; return e;
} }

Loading…
Cancel
Save