3232
3333#include < atomic>
3434
35+ #include " ir/debug.h"
3536#include " ir/literal-utils.h"
3637#include " ir/module-utils.h"
3738#include " ir/utils.h"
@@ -175,7 +176,7 @@ doInlining(Module* module, Function* into, InliningAction& action) {
175176 auto * block = Builder (*module ).makeBlock ();
176177 block->name = Name (std::string (" __inlined_func$" ) + from->name .str );
177178 *action.callSite = block;
178- // set up a locals mapping
179+ // Prepare to update the inlined code's locals and other things.
179180 struct Updater : public PostWalker <Updater> {
180181 std::map<Index, Index> localMapping;
181182 Name returnName;
@@ -193,33 +194,37 @@ doInlining(Module* module, Function* into, InliningAction& action) {
193194 } updater;
194195 updater.returnName = block->name ;
195196 updater.builder = &builder;
197+ // Set up a locals mapping
196198 for (Index i = 0 ; i < from->getNumLocals (); i++) {
197199 updater.localMapping [i] = builder.addVar (into, from->getLocalType (i));
198200 }
199- // assign the operands into the params
201+ // Assign the operands into the params
200202 for (Index i = 0 ; i < from->params .size (); i++) {
201203 block->list .push_back (
202204 builder.makeLocalSet (updater.localMapping [i], call->operands [i]));
203205 }
204- // zero out the vars (as we may be in a loop, and may depend on their
206+ // Zero out the vars (as we may be in a loop, and may depend on their
205207 // zero-init value
206208 for (Index i = 0 ; i < from->vars .size (); i++) {
207209 block->list .push_back (
208210 builder.makeLocalSet (updater.localMapping [from->getVarIndexBase () + i],
209211 LiteralUtils::makeZero (from->vars [i], *module )));
210212 }
211- // generate and update the inlined contents
213+ // Generate and update the inlined contents
212214 auto * contents = ExpressionManipulator::copy (from->body , *module );
215+ if (!from->debugLocations .empty ()) {
216+ debug::copyDebugInfo (from->body , contents, from, into);
217+ }
213218 updater.walk (contents);
214219 block->list .push_back (contents);
215220 block->type = call->type ;
216- // if the function returned a value, we just set the block containing the
221+ // If the function returned a value, we just set the block containing the
217222 // inlined code to have that type. or, if the function was void and
218223 // contained void, that is fine too. a bad case is a void function in which
219224 // we have unreachable code, so we would be replacing a void call with an
220225 // unreachable; we need to handle
221226 if (contents->type == unreachable && block->type == none) {
222- // make the block reachable by adding a break to it
227+ // Make the block reachable by adding a break to it
223228 block->list .push_back (builder.makeBreak (block->name ));
224229 }
225230 return block;
0 commit comments