forked from M-Labs/artiq
1
0
Fork 0

llvm_ir_gen: fix now with now_pinning & little-endian target

This commit is contained in:
occheung 2021-08-24 17:08:34 +08:00
parent 8fa47b8119
commit d623acc29d
1 changed files with 14 additions and 4 deletions

View File

@ -1103,6 +1103,14 @@ class LLVMIRGenerator:
return self.map(insn.operands[0]) return self.map(insn.operands[0])
elif insn.op == "now_mu": elif insn.op == "now_mu":
if self.target.now_pinning: if self.target.now_pinning:
# Word swap now.old for little endian target
# Most significant word is stored in lower address (see generated csr.rs)
if self.target.little_endian:
llnow_raw = self.llbuilder.load(self.llbuiltin("now"), name=insn.name)
llnow_lo = self.llbuilder.shl(llnow_raw, ll.Constant(lli64, 32))
llnow_hi = self.llbuilder.lshr(llnow_raw, ll.Constant(lli64, 32))
return self.llbuilder.or_(llnow_lo, llnow_hi)
else:
return self.llbuilder.load(self.llbuiltin("now"), name=insn.name) return self.llbuilder.load(self.llbuiltin("now"), name=insn.name)
else: else:
return self.llbuilder.call(self.llbuiltin("now_mu"), []) return self.llbuilder.call(self.llbuiltin("now_mu"), [])
@ -1114,8 +1122,6 @@ class LLVMIRGenerator:
lltime_lo = self.llbuilder.trunc(lltime, lli32) lltime_lo = self.llbuilder.trunc(lltime, lli32)
llnow_hiptr = self.llbuilder.bitcast(self.llbuiltin("now"), lli32.as_pointer()) llnow_hiptr = self.llbuilder.bitcast(self.llbuiltin("now"), lli32.as_pointer())
llnow_loptr = self.llbuilder.gep(llnow_hiptr, [self.llindex(1)]) llnow_loptr = self.llbuilder.gep(llnow_hiptr, [self.llindex(1)])
if self.target.little_endian:
lltime_hi, lltime_lo = lltime_lo, lltime_hi
llstore_hi = self.llbuilder.store_atomic(lltime_hi, llnow_hiptr, ordering="seq_cst", align=4) llstore_hi = self.llbuilder.store_atomic(lltime_hi, llnow_hiptr, ordering="seq_cst", align=4)
llstore_lo = self.llbuilder.store_atomic(lltime_lo, llnow_loptr, ordering="seq_cst", align=4) llstore_lo = self.llbuilder.store_atomic(lltime_lo, llnow_loptr, ordering="seq_cst", align=4)
return llstore_lo return llstore_lo
@ -1127,13 +1133,17 @@ class LLVMIRGenerator:
if self.target.now_pinning: if self.target.now_pinning:
llnowptr = self.llbuiltin("now") llnowptr = self.llbuiltin("now")
llnow = self.llbuilder.load(llnowptr, name="now.old") llnow = self.llbuilder.load(llnowptr, name="now.old")
# Word swap now.old for little endian target
# Most significant word is stored in lower address (see generated csr.rs)
if self.target.little_endian:
llnow_lo = self.llbuilder.shl(llnow, ll.Constant(lli64, 32))
llnow_hi = self.llbuilder.lshr(llnow, ll.Constant(lli64, 32))
llnow = self.llbuilder.or_(llnow_lo, llnow_hi)
lladjusted = self.llbuilder.add(llnow, llinterval, name="now.new") lladjusted = self.llbuilder.add(llnow, llinterval, name="now.new")
lladjusted_hi = self.llbuilder.trunc(self.llbuilder.lshr(lladjusted, ll.Constant(lli64, 32)), lli32) lladjusted_hi = self.llbuilder.trunc(self.llbuilder.lshr(lladjusted, ll.Constant(lli64, 32)), lli32)
lladjusted_lo = self.llbuilder.trunc(lladjusted, lli32) lladjusted_lo = self.llbuilder.trunc(lladjusted, lli32)
llnow_hiptr = self.llbuilder.bitcast(llnowptr, lli32.as_pointer()) llnow_hiptr = self.llbuilder.bitcast(llnowptr, lli32.as_pointer())
llnow_loptr = self.llbuilder.gep(llnow_hiptr, [self.llindex(1)]) llnow_loptr = self.llbuilder.gep(llnow_hiptr, [self.llindex(1)])
if self.target.little_endian:
lladjusted_hi, lladjusted_lo = lladjusted_lo, lladjusted_hi
llstore_hi = self.llbuilder.store_atomic(lladjusted_hi, llnow_hiptr, ordering="seq_cst", align=4) llstore_hi = self.llbuilder.store_atomic(lladjusted_hi, llnow_hiptr, ordering="seq_cst", align=4)
llstore_lo = self.llbuilder.store_atomic(lladjusted_lo, llnow_loptr, ordering="seq_cst", align=4) llstore_lo = self.llbuilder.store_atomic(lladjusted_lo, llnow_loptr, ordering="seq_cst", align=4)
return llstore_lo return llstore_lo