Rinaldini Julien via llvm-dev
2015-Oct-05 09:25 UTC
[llvm-dev] Swift to IR, generates wrong IR
Hi,
I have a simple swift code from which I generate IR code with ‘swiftc test.swift
-emit-ir -o test.ll'
When I try to run the .ll file or apply optimization with opt, I get errors like
this one:
lli: test.ll:548:110: error: expected instruction opcode
%9 = cmpxchg i64* bitcast (%swift.type*** @field_type_vector_TipCalculator to
i64*), i64 0, i64 %8 seq_cst seq_cst
^
I know swift is not part of the LLVM oss project, but is this problem coming
from swift generating wrong IR code or is this a LLVM bug (or maybe I’m just
doing something wrong)?
Cheers,
ps: this is the swift code I try running:
class TipCalculator {
// 2
let total: Double
let taxPct: Double
let subtotal: Double
// 3
init(total: Double, taxPct: Double) {a
self.total = total
self.taxPct = taxPct
subtotal = total / (taxPct + 1)
}
// 4
func calcTipWithTipPct(tipPct: Double) -> Double {a
return subtotal * tipPct
}
// 5
func printPossibleTips() {
print("15%: \(calcTipWithTipPct(0.15))")
print("18%: \(calcTipWithTipPct(0.18))")
print("20%: \(calcTipWithTipPct(0.20))")
}
}
// 6
let tipCalc = TipCalculator(total: 33.25, taxPct: 0.06)
tipCalc.printPossibleTips()
Rinaldini Julien via llvm-dev
2015-Oct-05 09:49 UTC
[llvm-dev] Swift to IR, generates wrong IR
Sorry, the error is (the previous one was from Apple’s lli):
Documents/strong.codes/code/build/obfuscator-llvm/bin/opt: test.ll:57:203:
error: expected comma after getelementptr's type
@_METACLASS_DATA__TtC4test13TipCalculator = private constant { i32, i32, i32,
i32, i8*, i8*, i8*, i8*, i8*, i8*, i8* } { i32 129, i32 40, i32 40, i32 0, i8*
null, i8* getelementptr inbounds ([25 x i8]* @7, i64 0, i64 0), i8* null, i8*
null, i8* null, i8* null, i8* null }, section "__DATA, __objc_const",
align 8
^
> On 05 Oct 2015, at 11:25, Rinaldini Julien via llvm-dev <llvm-dev at
lists.llvm.org> wrote:
>
> Hi,
> I have a simple swift code from which I generate IR code with ‘swiftc
test.swift -emit-ir -o test.ll'
> When I try to run the .ll file or apply optimization with opt, I get errors
like this one:
>
> lli: test.ll:548:110: error: expected instruction opcode
> %9 = cmpxchg i64* bitcast (%swift.type*** @field_type_vector_TipCalculator
to i64*), i64 0, i64 %8 seq_cst seq_cst
>
^
> I know swift is not part of the LLVM oss project, but is this problem
coming from swift generating wrong IR code or is this a LLVM bug (or maybe I’m
just doing something wrong)?
>
> Cheers,
>
> ps: this is the swift code I try running:
>
> class TipCalculator {
>
> // 2
> let total: Double
> let taxPct: Double
> let subtotal: Double
>
> // 3
> init(total: Double, taxPct: Double) {a
> self.total = total
> self.taxPct = taxPct
> subtotal = total / (taxPct + 1)
> }
>
> // 4
> func calcTipWithTipPct(tipPct: Double) -> Double {a
> return subtotal * tipPct
> }
>
> // 5
> func printPossibleTips() {
> print("15%: \(calcTipWithTipPct(0.15))")
> print("18%: \(calcTipWithTipPct(0.18))")
> print("20%: \(calcTipWithTipPct(0.20))")
> }
>
> }
>
> // 6
> let tipCalc = TipCalculator(total: 33.25, taxPct: 0.06)
> tipCalc.printPossibleTips()
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Björn Steinbrink via llvm-dev
2015-Oct-05 10:27 UTC
[llvm-dev] Swift to IR, generates wrong IR
Hi, 2015-10-05 11:49 GMT+02:00 Rinaldini Julien via llvm-dev <llvm-dev at lists.llvm.org>:> Sorry, the error is (the previous one was from Apple’s lli): > > Documents/strong.codes/code/build/obfuscator-llvm/bin/opt: test.ll:57:203: error: expected comma after getelementptr's type > @_METACLASS_DATA__TtC4test13TipCalculator = private constant { i32, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i8*, i8* } { i32 129, i32 40, i32 40, i32 0, i8* null, i8* getelementptr inbounds ([25 x i8]* @7, i64 0, i64 0), i8* null, i8* null, i8* null, i8* null, i8* null }, section "__DATA, __objc_const", align 8The IR format is not stable and it seems like Swift is using an LLVM < 3.7, while your opt executable is from LLVM 3.7. The `getelementptr` instruction (besides others) now expects the pointer type to be given explicitly. I don't know Swift, but if you can get it to emit bitcode instead of IR, that should work AFAIK. Looking at the command line, you probably need -emit-bc. Björn> ^ > >> On 05 Oct 2015, at 11:25, Rinaldini Julien via llvm-dev <llvm-dev at lists.llvm.org> wrote: >> >> Hi, >> I have a simple swift code from which I generate IR code with ‘swiftc test.swift -emit-ir -o test.ll' >> When I try to run the .ll file or apply optimization with opt, I get errors like this one: >> >> lli: test.ll:548:110: error: expected instruction opcode >> %9 = cmpxchg i64* bitcast (%swift.type*** @field_type_vector_TipCalculator to i64*), i64 0, i64 %8 seq_cst seq_cst >> ^ >> I know swift is not part of the LLVM oss project, but is this problem coming from swift generating wrong IR code or is this a LLVM bug (or maybe I’m just doing something wrong)? >> >> Cheers, >> >> ps: this is the swift code I try running: >> >> class TipCalculator { >> >> // 2 >> let total: Double >> let taxPct: Double >> let subtotal: Double >> >> // 3 >> init(total: Double, taxPct: Double) {a >> self.total = total >> self.taxPct = taxPct >> subtotal = total / (taxPct + 1) >> } >> >> // 4 >> func calcTipWithTipPct(tipPct: Double) -> Double {a >> return subtotal * tipPct >> } >> >> // 5 >> func printPossibleTips() { >> print("15%: \(calcTipWithTipPct(0.15))") >> print("18%: \(calcTipWithTipPct(0.18))") >> print("20%: \(calcTipWithTipPct(0.20))") >> } >> >> } >> >> // 6 >> let tipCalc = TipCalculator(total: 33.25, taxPct: 0.06) >> tipCalc.printPossibleTips() >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev