@@ -139,7 +139,7 @@ convert_constantExpr(
139139 /* FIXME: getAsInstruction is none const, forcing all llvm parameters to be none const */
140140 /* FIXME: The invocation of getAsInstruction() introduces a memory leak. */
141141 auto instruction = c->getAsInstruction ();
142- auto v = ConvertInstruction (instruction, tacs, ctx);
142+ auto v = convertInstruction (instruction, tacs, ctx);
143143 instruction->dropAllReferences ();
144144 return v;
145145}
@@ -1266,60 +1266,84 @@ convert(::llvm::Instruction * instruction, tacsvector_t & tacs, Context & ctx)
12661266}
12671267
12681268const Variable *
1269- ConvertInstruction (
1270- ::llvm::Instruction * i ,
1271- std::vector<std::unique_ptr<llvm:: ThreeAddressCode>> & tacs ,
1272- Context & ctx )
1269+ convertInstruction (
1270+ ::llvm::Instruction * instruction ,
1271+ std::vector<std::unique_ptr<ThreeAddressCode>> & threeAddressCodes ,
1272+ Context & context )
12731273{
1274- if (i->isCast ())
1275- return convert_cast_instruction (i, tacs, ctx);
1276-
1277- static std::unordered_map<
1278- unsigned ,
1279- const Variable * (*)(::llvm::Instruction *,
1280- std::vector<std::unique_ptr<llvm::ThreeAddressCode>> &,
1281- Context &)>
1282- map ({ { ::llvm::Instruction::Ret, convert_return_instruction },
1283- { ::llvm::Instruction::Br, ConvertBranchInstruction },
1284- { ::llvm::Instruction::Switch, ConvertSwitchInstruction },
1285- { ::llvm::Instruction::Unreachable, convert_unreachable_instruction },
1286- { ::llvm::Instruction::Add, convert<::llvm::BinaryOperator> },
1287- { ::llvm::Instruction::And, convert<::llvm::BinaryOperator> },
1288- { ::llvm::Instruction::AShr, convert<::llvm::BinaryOperator> },
1289- { ::llvm::Instruction::Sub, convert<::llvm::BinaryOperator> },
1290- { ::llvm::Instruction::UDiv, convert<::llvm::BinaryOperator> },
1291- { ::llvm::Instruction::SDiv, convert<::llvm::BinaryOperator> },
1292- { ::llvm::Instruction::URem, convert<::llvm::BinaryOperator> },
1293- { ::llvm::Instruction::SRem, convert<::llvm::BinaryOperator> },
1294- { ::llvm::Instruction::Shl, convert<::llvm::BinaryOperator> },
1295- { ::llvm::Instruction::LShr, convert<::llvm::BinaryOperator> },
1296- { ::llvm::Instruction::Or, convert<::llvm::BinaryOperator> },
1297- { ::llvm::Instruction::Xor, convert<::llvm::BinaryOperator> },
1298- { ::llvm::Instruction::Mul, convert<::llvm::BinaryOperator> },
1299- { ::llvm::Instruction::FAdd, convert<::llvm::BinaryOperator> },
1300- { ::llvm::Instruction::FSub, convert<::llvm::BinaryOperator> },
1301- { ::llvm::Instruction::FMul, convert<::llvm::BinaryOperator> },
1302- { ::llvm::Instruction::FDiv, convert<::llvm::BinaryOperator> },
1303- { ::llvm::Instruction::FRem, convert<::llvm::BinaryOperator> },
1304- { ::llvm::Instruction::FNeg, convert<::llvm::UnaryOperator> },
1305- { ::llvm::Instruction::ICmp, convert<::llvm::ICmpInst> },
1306- { ::llvm::Instruction::FCmp, convert_fcmp_instruction },
1307- { ::llvm::Instruction::Load, convert_load_instruction },
1308- { ::llvm::Instruction::Store, convert_store_instruction },
1309- { ::llvm::Instruction::PHI, ConvertPhiInstruction },
1310- { ::llvm::Instruction::GetElementPtr, convert_getelementptr_instruction },
1311- { ::llvm::Instruction::Call, convert_call_instruction },
1312- { ::llvm::Instruction::Select, convert_select_instruction },
1313- { ::llvm::Instruction::Alloca, convert_alloca_instruction },
1314- { ::llvm::Instruction::ExtractValue, convert_extractvalue },
1315- { ::llvm::Instruction::ExtractElement, convert_extractelement_instruction },
1316- { ::llvm::Instruction::ShuffleVector, convert<::llvm::ShuffleVectorInst> },
1317- { ::llvm::Instruction::InsertElement, convert_insertelement_instruction } });
1318-
1319- if (map.find (i->getOpcode ()) == map.end ())
1320- JLM_UNREACHABLE (util::strfmt (i->getOpcodeName (), " is not supported." ).c_str ());
1321-
1322- return map[i->getOpcode ()](i, tacs, ctx);
1274+ switch (instruction->getOpcode ())
1275+ {
1276+ case ::llvm::Instruction::Trunc:
1277+ case ::llvm::Instruction::ZExt:
1278+ case ::llvm::Instruction::UIToFP:
1279+ case ::llvm::Instruction::SIToFP:
1280+ case ::llvm::Instruction::SExt:
1281+ case ::llvm::Instruction::PtrToInt:
1282+ case ::llvm::Instruction::IntToPtr:
1283+ case ::llvm::Instruction::FPTrunc:
1284+ case ::llvm::Instruction::FPToSI:
1285+ case ::llvm::Instruction::FPToUI:
1286+ case ::llvm::Instruction::FPExt:
1287+ case ::llvm::Instruction::BitCast:
1288+ return convert_cast_instruction (instruction, threeAddressCodes, context);
1289+ case ::llvm::Instruction::Add:
1290+ case ::llvm::Instruction::And:
1291+ case ::llvm::Instruction::AShr:
1292+ case ::llvm::Instruction::Sub:
1293+ case ::llvm::Instruction::UDiv:
1294+ case ::llvm::Instruction::SDiv:
1295+ case ::llvm::Instruction::URem:
1296+ case ::llvm::Instruction::SRem:
1297+ case ::llvm::Instruction::Shl:
1298+ case ::llvm::Instruction::LShr:
1299+ case ::llvm::Instruction::Or:
1300+ case ::llvm::Instruction::Xor:
1301+ case ::llvm::Instruction::Mul:
1302+ case ::llvm::Instruction::FAdd:
1303+ case ::llvm::Instruction::FSub:
1304+ case ::llvm::Instruction::FMul:
1305+ case ::llvm::Instruction::FDiv:
1306+ case ::llvm::Instruction::FRem:
1307+ return convert<::llvm::BinaryOperator>(instruction, threeAddressCodes, context);
1308+ case ::llvm::Instruction::Ret:
1309+ return convert_return_instruction (instruction, threeAddressCodes, context);
1310+ case ::llvm::Instruction::Br:
1311+ return ConvertBranchInstruction (instruction, threeAddressCodes, context);
1312+ case ::llvm::Instruction::Switch:
1313+ return ConvertSwitchInstruction (instruction, threeAddressCodes, context);
1314+ case ::llvm::Instruction::Unreachable:
1315+ return convert_unreachable_instruction (instruction, threeAddressCodes, context);
1316+ case ::llvm::Instruction::FNeg:
1317+ return convert<::llvm::UnaryOperator>(instruction, threeAddressCodes, context);
1318+ case ::llvm::Instruction::ICmp:
1319+ return convert<::llvm::ICmpInst>(instruction, threeAddressCodes, context);
1320+ case ::llvm::Instruction::FCmp:
1321+ return convert_fcmp_instruction (instruction, threeAddressCodes, context);
1322+ case ::llvm::Instruction::Load:
1323+ return convert_load_instruction (instruction, threeAddressCodes, context);
1324+ case ::llvm::Instruction::Store:
1325+ return convert_store_instruction (instruction, threeAddressCodes, context);
1326+ case ::llvm::Instruction::PHI:
1327+ return ConvertPhiInstruction (instruction, threeAddressCodes, context);
1328+ case ::llvm::Instruction::GetElementPtr:
1329+ return convert_getelementptr_instruction (instruction, threeAddressCodes, context);
1330+ case ::llvm::Instruction::Call:
1331+ return convert_call_instruction (instruction, threeAddressCodes, context);
1332+ case ::llvm::Instruction::Select:
1333+ return convert_select_instruction (instruction, threeAddressCodes, context);
1334+ case ::llvm::Instruction::Alloca:
1335+ return convert_alloca_instruction (instruction, threeAddressCodes, context);
1336+ case ::llvm::Instruction::ExtractValue:
1337+ return convert_extractvalue (instruction, threeAddressCodes, context);
1338+ case ::llvm::Instruction::ExtractElement:
1339+ return convert_extractelement_instruction (instruction, threeAddressCodes, context);
1340+ case ::llvm::Instruction::ShuffleVector:
1341+ return convert<::llvm::ShuffleVectorInst>(instruction, threeAddressCodes, context);
1342+ case ::llvm::Instruction::InsertElement:
1343+ return convert_insertelement_instruction (instruction, threeAddressCodes, context);
1344+ default :
1345+ throw std::runtime_error (util::strfmt (instruction->getOpcodeName (), " is not supported." ));
1346+ }
13231347}
13241348
13251349}
0 commit comments