<!DOCTYPE HTML><html>
<head>
<meta name="Generator" content="Amazon WorkMail v3.0-4199">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Proper way to load pre-generated LLVM IR into JIT module and dedup type definitions?</title>
</head>
<body>
<p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">What is the proper way to load a set of pre-generated LLVM IR and make it available to runtime JIT modules such that the same types aren't given new names and inlining and const propagation can still take place?</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px"> </p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">My attempt so far:</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">I compile a set of C functions to LLVM IR offline via<span> '</span>clang -c -emit-llvm -S -ffast-math -msse2 -O3 -o MyLib.ll MyLib.c'</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">For each runtime JIT module, I load the generated LLVM IR via<span> </span>llvm::parseIRFile()<span> </span>and "paste" it into the runtime JIT module via<span> </span>llvm::Linker::linkModules().</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">This works fine for the first JIT module, but not for subsequent JIT modules created. Each time<span> </span>llvm::parseIRFile()<span> </span>is called, the resulting module's type definitions in the IR is given new names.</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px"> </p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">For example, offline MyLib.ll looks like this:</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">%struct.A = type { <4 x float> }</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">define <4 x float> @Foo(A*)(%struct.A* nocapture readonly) { ... }</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px"> </p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">The resulting module from the first call to<span> </span>llvm::parseIRFile()<span> </span>looks exactly as the offline version. The resulting module from the<span> </span><strong>second</strong><span> </span>call to<span> </span>llvm:parseIRFile()<span> </span>instead looks like:</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">%struct.A<strong>.1</strong> = type { <4 x float> } define <4 x float> @Foo(A*)(%struct.A.1* nocapture readonly) { ... }</p><p style="background-color:#ffffff; border:0px; color:#242729; font-family:Arial,"Helvetica Neue",Helvetica,sans-serif; font-size:15px; font-stretch:inherit; font-style:normal; font-variant-caps:normal; font-variant-east-asian:inherit; font-variant-ligatures:normal; font-variant-numeric:inherit; font-weight:400; margin:0px 0px 1em; padding:0px; text-align:left; text-decoration-color:initial; text-decoration-style:initial; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px">Note that<span> </span>%struct.A<span> </span>was renamed to<span> </span>%struct.A.1. The runtime JIT module continues to generate code using<span> </span>%struct.A<span> </span>thus fails to call<span> </span>Foo()<span> </span>since its parameter is %struct.A.1<span> </span>instead.</p>
</body>
</html>