blob: 6ddd6c1d74022654428e772690985581b4685850 [file] [log] [blame]
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001//===-- IRForTarget.cpp -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Expression/IRForTarget.h"
11
12#include "llvm/Support/raw_ostream.h"
13#include "llvm/InstrTypes.h"
Sean Callanan8bce6652010-07-13 21:41:46 +000014#include "llvm/Instructions.h"
Sean Callanan3cb1fd82010-09-28 23:55:00 +000015#include "llvm/Intrinsics.h"
Sean Callanan5cf4a1c2010-07-03 01:35:46 +000016#include "llvm/Module.h"
Sean Callanan8bce6652010-07-13 21:41:46 +000017#include "llvm/Target/TargetData.h"
Sean Callanan82b74c82010-08-12 01:56:52 +000018#include "llvm/ValueSymbolTable.h"
Sean Callanan8bce6652010-07-13 21:41:46 +000019
20#include "clang/AST/ASTContext.h"
Sean Callanan5cf4a1c2010-07-03 01:35:46 +000021
22#include "lldb/Core/dwarf.h"
23#include "lldb/Core/Log.h"
24#include "lldb/Core/Scalar.h"
25#include "lldb/Core/StreamString.h"
26#include "lldb/Expression/ClangExpressionDeclMap.h"
27
28#include <map>
29
30using namespace llvm;
31
Sean Callanan3351dac2010-08-18 18:50:51 +000032static char ID;
33
34IRForTarget::IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map,
Sean Callanan65dafa82010-08-27 01:01:44 +000035 const TargetData *target_data,
Sean Callanane8a59a82010-09-13 21:34:21 +000036 bool resolve_vars,
Sean Callanan65dafa82010-08-27 01:01:44 +000037 const char *func_name) :
Sean Callanan47a5c4c2010-09-23 03:01:22 +000038 ModulePass(ID),
Sean Callanan8bce6652010-07-13 21:41:46 +000039 m_decl_map(decl_map),
Sean Callananf5857a02010-07-31 01:32:05 +000040 m_target_data(target_data),
Sean Callanan65dafa82010-08-27 01:01:44 +000041 m_sel_registerName(NULL),
Sean Callanane8a59a82010-09-13 21:34:21 +000042 m_func_name(func_name),
43 m_resolve_vars(resolve_vars)
Sean Callanan5cf4a1c2010-07-03 01:35:46 +000044{
45}
46
Sean Callanana48fe162010-08-11 03:57:18 +000047/* A handy utility function used at several places in the code */
48
49static std::string
50PrintValue(Value *V, bool truncate = false)
51{
52 std::string s;
53 raw_string_ostream rso(s);
54 V->print(rso);
55 rso.flush();
56 if (truncate)
57 s.resize(s.length() - 1);
58 return s;
59}
60
Sean Callanan5cf4a1c2010-07-03 01:35:46 +000061IRForTarget::~IRForTarget()
62{
63}
64
Sean Callanan82b74c82010-08-12 01:56:52 +000065bool
66IRForTarget::createResultVariable(llvm::Module &M,
67 llvm::Function &F)
68{
69 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
70
Sean Callanane8a59a82010-09-13 21:34:21 +000071 if (!m_resolve_vars)
72 return true;
73
74 // Find the result variable. If it doesn't exist, we can give up right here.
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000075
76 ValueSymbolTable& value_symbol_table = M.getValueSymbolTable();
77
78 const char *result_name = NULL;
79
80 for (ValueSymbolTable::iterator vi = value_symbol_table.begin(), ve = value_symbol_table.end();
81 vi != ve;
82 ++vi)
83 {
Sean Callananc04743d2010-09-28 21:13:03 +000084 if (strstr(vi->first(), "___clang_expr_result") &&
85 !strstr(vi->first(), "GV"))
86 {
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000087 result_name = vi->first();
Sean Callananc04743d2010-09-28 21:13:03 +000088 break;
89 }
Sean Callanan3c9c5eb2010-09-21 00:44:12 +000090 }
91
92 if (!result_name)
93 {
94 if (log)
95 log->PutCString("Couldn't find result variable");
96
97 return true;
98 }
99
Sean Callananc04743d2010-09-28 21:13:03 +0000100 if (log)
101 log->Printf("Result name: %s", result_name);
102
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000103 Value *result_value = M.getNamedValue(result_name);
Sean Callanan82b74c82010-08-12 01:56:52 +0000104
105 if (!result_value)
106 {
107 if (log)
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000108 log->PutCString("Result variable had no data");
Sean Callanane8a59a82010-09-13 21:34:21 +0000109
Sean Callanan3c9c5eb2010-09-21 00:44:12 +0000110 return false;
Sean Callanan82b74c82010-08-12 01:56:52 +0000111 }
Sean Callanane8a59a82010-09-13 21:34:21 +0000112
Sean Callanan82b74c82010-08-12 01:56:52 +0000113 if (log)
114 log->Printf("Found result in the IR: %s", PrintValue(result_value, false).c_str());
115
116 GlobalVariable *result_global = dyn_cast<GlobalVariable>(result_value);
117
118 if (!result_global)
119 {
120 if (log)
121 log->PutCString("Result variable isn't a GlobalVariable");
122 return false;
123 }
124
125 // Find the metadata and follow it to the VarDecl
126
127 NamedMDNode *named_metadata = M.getNamedMetadata("clang.global.decl.ptrs");
128
129 if (!named_metadata)
130 {
131 if (log)
132 log->PutCString("No global metadata");
133
134 return false;
135 }
136
137 unsigned num_nodes = named_metadata->getNumOperands();
138 unsigned node_index;
139
140 MDNode *metadata_node = NULL;
141
142 for (node_index = 0;
143 node_index < num_nodes;
144 ++node_index)
145 {
146 metadata_node = named_metadata->getOperand(node_index);
147
148 if (metadata_node->getNumOperands() != 2)
149 continue;
150
151 if (metadata_node->getOperand(0) == result_global)
152 break;
153 }
154
155 if (!metadata_node)
156 {
157 if (log)
158 log->PutCString("Couldn't find result metadata");
159 return false;
160 }
161
162 ConstantInt *constant_int = dyn_cast<ConstantInt>(metadata_node->getOperand(1));
163
164 uint64_t result_decl_intptr = constant_int->getZExtValue();
165
166 clang::VarDecl *result_decl = reinterpret_cast<clang::VarDecl *>(result_decl_intptr);
167
168 // Get the next available result name from m_decl_map and create the persistent
169 // variable for it
170
171 lldb_private::TypeFromParser result_decl_type (result_decl->getType().getAsOpaquePtr(),
172 &result_decl->getASTContext());
173 std::string new_result_name;
174
175 m_decl_map->GetPersistentResultName(new_result_name);
Sean Callanan8c127202010-08-23 23:09:38 +0000176 m_decl_map->AddPersistentVariable(result_decl, new_result_name.c_str(), result_decl_type);
Sean Callanan82b74c82010-08-12 01:56:52 +0000177
178 if (log)
179 log->Printf("Creating a new result global: %s", new_result_name.c_str());
180
181 // Construct a new result global and set up its metadata
182
183 GlobalVariable *new_result_global = new GlobalVariable(M,
184 result_global->getType()->getElementType(),
185 false, /* not constant */
186 GlobalValue::ExternalLinkage,
187 NULL, /* no initializer */
188 new_result_name.c_str());
189
190 // It's too late in compilation to create a new VarDecl for this, but we don't
191 // need to. We point the metadata at the old VarDecl. This creates an odd
192 // anomaly: a variable with a Value whose name is something like $0 and a
193 // Decl whose name is ___clang_expr_result. This condition is handled in
194 // ClangExpressionDeclMap::DoMaterialize, and the name of the variable is
195 // fixed up.
196
197 ConstantInt *new_constant_int = ConstantInt::get(constant_int->getType(),
198 result_decl_intptr,
199 false);
200
201 llvm::Value* values[2];
202 values[0] = new_result_global;
203 values[1] = new_constant_int;
204
205 MDNode *persistent_global_md = MDNode::get(M.getContext(), values, 2);
206 named_metadata->addOperand(persistent_global_md);
207
208 if (log)
Sean Callanan2e2db532010-09-07 22:43:19 +0000209 log->Printf("Replacing %s with %s",
210 PrintValue(result_global).c_str(),
Sean Callanan82b74c82010-08-12 01:56:52 +0000211 PrintValue(new_result_global).c_str());
Sean Callanan2e2db532010-09-07 22:43:19 +0000212
213 if (result_global->hasNUses(0))
214 {
215 // We need to synthesize a store for this variable, because otherwise
216 // there's nothing to put into its equivalent persistent variable.
Sean Callanan82b74c82010-08-12 01:56:52 +0000217
Sean Callanan2e2db532010-09-07 22:43:19 +0000218 BasicBlock &entry_block(F.getEntryBlock());
219 Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
220
221 if (!first_entry_instruction)
222 return false;
223
224 if (!result_global->hasInitializer())
225 {
226 if (log)
227 log->Printf("Couldn't find initializer for unused variable");
228 return false;
229 }
230
231 Constant *initializer = result_global->getInitializer();
232
233 StoreInst *synthesized_store = new StoreInst::StoreInst(initializer,
234 new_result_global,
235 first_entry_instruction);
236
237 if (log)
238 log->Printf("Synthesized result store %s\n", PrintValue(synthesized_store).c_str());
239 }
240 else
241 {
242 result_global->replaceAllUsesWith(new_result_global);
243 }
244
Sean Callanan82b74c82010-08-12 01:56:52 +0000245 result_global->eraseFromParent();
246
247 return true;
248}
249
Sean Callananf5857a02010-07-31 01:32:05 +0000250static bool isObjCSelectorRef(Value *V)
251{
252 GlobalVariable *GV = dyn_cast<GlobalVariable>(V);
253
254 if (!GV || !GV->hasName() || !GV->getName().startswith("\01L_OBJC_SELECTOR_REFERENCES_"))
255 return false;
256
257 return true;
258}
259
260bool
261IRForTarget::RewriteObjCSelector(Instruction* selector_load,
262 Module &M)
263{
264 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
265
266 LoadInst *load = dyn_cast<LoadInst>(selector_load);
267
268 if (!load)
269 return false;
270
271 // Unpack the message name from the selector. In LLVM IR, an objc_msgSend gets represented as
272 //
273 // %tmp = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_" ; <i8*>
274 // %call = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %obj, i8* %tmp, ...) ; <i8*>
275 //
276 // where %obj is the object pointer and %tmp is the selector.
277 //
278 // @"\01L_OBJC_SELECTOR_REFERENCES_" is a pointer to a character array called @"\01L_OBJC_METH_VAR_NAME_".
279 // @"\01L_OBJC_METH_VAR_NAME_" contains the string.
280
281 // Find the pointer's initializer (a ConstantExpr with opcode GetElementPtr) and get the string from its target
282
283 GlobalVariable *_objc_selector_references_ = dyn_cast<GlobalVariable>(load->getPointerOperand());
284
285 if (!_objc_selector_references_ || !_objc_selector_references_->hasInitializer())
286 return false;
287
288 Constant *osr_initializer = _objc_selector_references_->getInitializer();
289
290 ConstantExpr *osr_initializer_expr = dyn_cast<ConstantExpr>(osr_initializer);
291
292 if (!osr_initializer_expr || osr_initializer_expr->getOpcode() != Instruction::GetElementPtr)
293 return false;
294
295 Value *osr_initializer_base = osr_initializer_expr->getOperand(0);
296
297 if (!osr_initializer_base)
298 return false;
299
300 // Find the string's initializer (a ConstantArray) and get the string from it
301
302 GlobalVariable *_objc_meth_var_name_ = dyn_cast<GlobalVariable>(osr_initializer_base);
303
304 if (!_objc_meth_var_name_ || !_objc_meth_var_name_->hasInitializer())
305 return false;
306
307 Constant *omvn_initializer = _objc_meth_var_name_->getInitializer();
308
309 ConstantArray *omvn_initializer_array = dyn_cast<ConstantArray>(omvn_initializer);
310
311 if (!omvn_initializer_array->isString())
312 return false;
313
314 std::string omvn_initializer_string = omvn_initializer_array->getAsString();
315
316 if (log)
317 log->Printf("Found Objective-C selector reference %s", omvn_initializer_string.c_str());
318
319 // Construct a call to sel_registerName
320
321 if (!m_sel_registerName)
322 {
323 uint64_t srN_addr;
324
325 if (!m_decl_map->GetFunctionAddress("sel_registerName", srN_addr))
326 return false;
327
328 // Build the function type: struct objc_selector *sel_registerName(uint8_t*)
329
330 // The below code would be "more correct," but in actuality what's required is uint8_t*
331 //Type *sel_type = StructType::get(M.getContext());
332 //Type *sel_ptr_type = PointerType::getUnqual(sel_type);
333 const Type *sel_ptr_type = Type::getInt8PtrTy(M.getContext());
334
335 std::vector <const Type *> srN_arg_types;
336 srN_arg_types.push_back(Type::getInt8PtrTy(M.getContext()));
337 llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false);
338
339 // Build the constant containing the pointer to the function
340 const IntegerType *intptr_ty = Type::getIntNTy(M.getContext(),
341 (M.getPointerSize() == Module::Pointer64) ? 64 : 32);
342 PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type);
343 Constant *srN_addr_int = ConstantInt::get(intptr_ty, srN_addr, false);
344 m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty);
345 }
346
347 SmallVector <Value*, 1> srN_arguments;
348
349 Constant *omvn_pointer = ConstantExpr::getBitCast(_objc_meth_var_name_, Type::getInt8PtrTy(M.getContext()));
350
351 srN_arguments.push_back(omvn_pointer);
352
353 CallInst *srN_call = CallInst::Create(m_sel_registerName,
354 srN_arguments.begin(),
355 srN_arguments.end(),
356 "srN",
357 selector_load);
358
359 // Replace the load with the call in all users
360
361 selector_load->replaceAllUsesWith(srN_call);
362
363 selector_load->eraseFromParent();
364
365 return true;
366}
367
368bool
369IRForTarget::rewriteObjCSelectors(Module &M,
370 BasicBlock &BB)
371{
372 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
373
374 BasicBlock::iterator ii;
375
376 typedef SmallVector <Instruction*, 2> InstrList;
377 typedef InstrList::iterator InstrIterator;
378
379 InstrList selector_loads;
380
381 for (ii = BB.begin();
382 ii != BB.end();
383 ++ii)
384 {
385 Instruction &inst = *ii;
386
387 if (LoadInst *load = dyn_cast<LoadInst>(&inst))
388 if (isObjCSelectorRef(load->getPointerOperand()))
389 selector_loads.push_back(&inst);
390 }
391
392 InstrIterator iter;
393
394 for (iter = selector_loads.begin();
395 iter != selector_loads.end();
396 ++iter)
397 {
398 if (!RewriteObjCSelector(*iter, M))
399 {
400 if(log)
401 log->PutCString("Couldn't rewrite a reference to an Objective-C selector");
402 return false;
403 }
404 }
405
406 return true;
407}
408
Sean Callanana48fe162010-08-11 03:57:18 +0000409bool
410IRForTarget::RewritePersistentAlloc(llvm::Instruction *persistent_alloc,
411 llvm::Module &M)
412{
413 AllocaInst *alloc = dyn_cast<AllocaInst>(persistent_alloc);
414
415 MDNode *alloc_md = alloc->getMetadata("clang.decl.ptr");
416
417 if (!alloc_md || !alloc_md->getNumOperands())
418 return false;
419
420 ConstantInt *constant_int = dyn_cast<ConstantInt>(alloc_md->getOperand(0));
421
422 if (!constant_int)
423 return false;
424
425 // We attempt to register this as a new persistent variable with the DeclMap.
426
427 uintptr_t ptr = constant_int->getZExtValue();
428
Sean Callanan82b74c82010-08-12 01:56:52 +0000429 clang::VarDecl *decl = reinterpret_cast<clang::VarDecl *>(ptr);
Sean Callanana48fe162010-08-11 03:57:18 +0000430
Sean Callanan82b74c82010-08-12 01:56:52 +0000431 lldb_private::TypeFromParser result_decl_type (decl->getType().getAsOpaquePtr(),
432 &decl->getASTContext());
433
Sean Callanan8c127202010-08-23 23:09:38 +0000434 if (!m_decl_map->AddPersistentVariable(decl, decl->getName().str().c_str(), result_decl_type))
Sean Callanana48fe162010-08-11 03:57:18 +0000435 return false;
436
437 GlobalVariable *persistent_global = new GlobalVariable(M,
438 alloc->getType()->getElementType(),
439 false, /* not constant */
440 GlobalValue::ExternalLinkage,
441 NULL, /* no initializer */
442 alloc->getName().str().c_str());
443
444 // What we're going to do here is make believe this was a regular old external
445 // variable. That means we need to make the metadata valid.
446
447 NamedMDNode *named_metadata = M.getNamedMetadata("clang.global.decl.ptrs");
448
449 llvm::Value* values[2];
450 values[0] = persistent_global;
451 values[1] = constant_int;
452
453 MDNode *persistent_global_md = MDNode::get(M.getContext(), values, 2);
454 named_metadata->addOperand(persistent_global_md);
455
456 alloc->replaceAllUsesWith(persistent_global);
457 alloc->eraseFromParent();
458
459 return true;
460}
461
462bool
463IRForTarget::rewritePersistentAllocs(llvm::Module &M,
464 llvm::BasicBlock &BB)
465{
Sean Callanane8a59a82010-09-13 21:34:21 +0000466 if (!m_resolve_vars)
467 return true;
468
Sean Callanana48fe162010-08-11 03:57:18 +0000469 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
470
471 BasicBlock::iterator ii;
472
473 typedef SmallVector <Instruction*, 2> InstrList;
474 typedef InstrList::iterator InstrIterator;
475
476 InstrList pvar_allocs;
477
478 for (ii = BB.begin();
479 ii != BB.end();
480 ++ii)
481 {
482 Instruction &inst = *ii;
483
484 if (AllocaInst *alloc = dyn_cast<AllocaInst>(&inst))
485 if (alloc->getName().startswith("$"))
486 pvar_allocs.push_back(alloc);
487 }
488
489 InstrIterator iter;
490
491 for (iter = pvar_allocs.begin();
492 iter != pvar_allocs.end();
493 ++iter)
494 {
495 if (!RewritePersistentAlloc(*iter, M))
496 {
497 if(log)
498 log->PutCString("Couldn't rewrite the creation of a persistent variable");
499 return false;
500 }
501 }
502
503 return true;
504}
505
Sean Callanan8bce6652010-07-13 21:41:46 +0000506static clang::NamedDecl *
Sean Callanan02fbafa2010-07-27 21:39:39 +0000507DeclForGlobalValue(Module &module,
508 GlobalValue *global_value)
Sean Callanan8bce6652010-07-13 21:41:46 +0000509{
510 NamedMDNode *named_metadata = module.getNamedMetadata("clang.global.decl.ptrs");
511
512 if (!named_metadata)
513 return NULL;
514
515 unsigned num_nodes = named_metadata->getNumOperands();
516 unsigned node_index;
517
518 for (node_index = 0;
519 node_index < num_nodes;
520 ++node_index)
521 {
522 MDNode *metadata_node = named_metadata->getOperand(node_index);
523
524 if (!metadata_node)
525 return NULL;
526
527 if (metadata_node->getNumOperands() != 2)
Sean Callanana48fe162010-08-11 03:57:18 +0000528 continue;
Sean Callanan8bce6652010-07-13 21:41:46 +0000529
530 if (metadata_node->getOperand(0) != global_value)
531 continue;
532
533 ConstantInt *constant_int = dyn_cast<ConstantInt>(metadata_node->getOperand(1));
534
535 if (!constant_int)
536 return NULL;
537
538 uintptr_t ptr = constant_int->getZExtValue();
539
540 return reinterpret_cast<clang::NamedDecl *>(ptr);
541 }
542
543 return NULL;
544}
545
546bool
547IRForTarget::MaybeHandleVariable(Module &M,
Sean Callanan02fbafa2010-07-27 21:39:39 +0000548 Value *V,
Sean Callanan8bce6652010-07-13 21:41:46 +0000549 bool Store)
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000550{
Sean Callananf5857a02010-07-31 01:32:05 +0000551 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
552
Sean Callananbc2928a2010-08-03 00:23:29 +0000553 if (ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(V))
554 {
Sean Callanan93a4b1a2010-08-04 01:02:13 +0000555 switch (constant_expr->getOpcode())
Sean Callananbc2928a2010-08-03 00:23:29 +0000556 {
Sean Callanan93a4b1a2010-08-04 01:02:13 +0000557 default:
558 break;
559 case Instruction::GetElementPtr:
560 case Instruction::BitCast:
Sean Callananbc2928a2010-08-03 00:23:29 +0000561 Value *s = constant_expr->getOperand(0);
562 MaybeHandleVariable(M, s, Store);
563 }
564 }
Sean Callanan8bce6652010-07-13 21:41:46 +0000565 if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(V))
Sean Callananf5857a02010-07-31 01:32:05 +0000566 {
Sean Callanan8bce6652010-07-13 21:41:46 +0000567 clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable);
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000568
Sean Callananf5857a02010-07-31 01:32:05 +0000569 if (!named_decl)
570 {
571 if (isObjCSelectorRef(V))
572 return true;
573
574 if (log)
575 log->Printf("Found global variable %s without metadata", global_variable->getName().str().c_str());
576 return false;
577 }
578
Sean Callanan810f22d2010-07-16 00:09:46 +0000579 std::string name = named_decl->getName().str();
580
581 void *qual_type = NULL;
Sean Callananf328c9f2010-07-20 23:31:16 +0000582 clang::ASTContext *ast_context = NULL;
Sean Callanan810f22d2010-07-16 00:09:46 +0000583
584 if (clang::ValueDecl *value_decl = dyn_cast<clang::ValueDecl>(named_decl))
Sean Callananf328c9f2010-07-20 23:31:16 +0000585 {
Sean Callanan810f22d2010-07-16 00:09:46 +0000586 qual_type = value_decl->getType().getAsOpaquePtr();
Sean Callananf328c9f2010-07-20 23:31:16 +0000587 ast_context = &value_decl->getASTContext();
588 }
Sean Callanan810f22d2010-07-16 00:09:46 +0000589 else
Sean Callananf328c9f2010-07-20 23:31:16 +0000590 {
Sean Callanan810f22d2010-07-16 00:09:46 +0000591 return false;
Sean Callananf328c9f2010-07-20 23:31:16 +0000592 }
593
Sean Callanan02fbafa2010-07-27 21:39:39 +0000594 const Type *value_type = global_variable->getType();
Sean Callanan8bce6652010-07-13 21:41:46 +0000595
596 size_t value_size = m_target_data->getTypeStoreSize(value_type);
597 off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
598
Sean Callanan8c127202010-08-23 23:09:38 +0000599 if (named_decl && !m_decl_map->AddValueToStruct(named_decl,
Sean Callanan45690fe2010-08-30 22:17:16 +0000600 name.c_str(),
Sean Callanan8c127202010-08-23 23:09:38 +0000601 V,
Sean Callananba992c52010-07-27 02:07:53 +0000602 value_size,
603 value_alignment))
Sean Callanan8bce6652010-07-13 21:41:46 +0000604 return false;
605 }
606
607 return true;
608}
609
610bool
Sean Callananba992c52010-07-27 02:07:53 +0000611IRForTarget::MaybeHandleCall(Module &M,
612 CallInst *C)
613{
614 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
615
Sean Callanan02fbafa2010-07-27 21:39:39 +0000616 Function *fun = C->getCalledFunction();
Sean Callananba992c52010-07-27 02:07:53 +0000617
618 if (fun == NULL)
Sean Callanan65af7342010-09-08 20:04:08 +0000619 {
620 Value *val = C->getCalledValue();
621
622 ConstantExpr *const_expr = dyn_cast<ConstantExpr>(val);
623
624 if (const_expr && const_expr->getOpcode() == Instruction::BitCast)
625 {
626 fun = dyn_cast<Function>(const_expr->getOperand(0));
627
628 if (!fun)
629 return true;
630 }
631 else
632 {
633 return true;
634 }
635 }
Sean Callananba992c52010-07-27 02:07:53 +0000636
Sean Callanan3cb1fd82010-09-28 23:55:00 +0000637 std::string str;
Sean Callananc04743d2010-09-28 21:13:03 +0000638
Sean Callanan3cb1fd82010-09-28 23:55:00 +0000639 if (fun->isIntrinsic())
Sean Callananc04743d2010-09-28 21:13:03 +0000640 {
Sean Callanan3cb1fd82010-09-28 23:55:00 +0000641 Intrinsic::ID intrinsic_id = (Intrinsic::ID)fun->getIntrinsicID();
Sean Callananc04743d2010-09-28 21:13:03 +0000642
Sean Callanan3cb1fd82010-09-28 23:55:00 +0000643 switch (intrinsic_id)
644 {
645 default:
646 if (log)
647 log->Printf("Unresolved intrinsic %s", Intrinsic::getName(intrinsic_id).c_str());
648 return false;
649 case Intrinsic::memcpy:
650 str = "memcpy";
651 break;
652 }
Sean Callananc04743d2010-09-28 21:13:03 +0000653
654 if (log)
Sean Callanan3cb1fd82010-09-28 23:55:00 +0000655 log->Printf("Resolved intrinsic name %s", str.c_str());
656 }
657 else
658 {
659 str = fun->getName().str();
Sean Callananc04743d2010-09-28 21:13:03 +0000660 }
661
Sean Callananba992c52010-07-27 02:07:53 +0000662 clang::NamedDecl *fun_decl = DeclForGlobalValue(M, fun);
Sean Callanan02fbafa2010-07-27 21:39:39 +0000663 uint64_t fun_addr;
Sean Callananf5857a02010-07-31 01:32:05 +0000664 Value **fun_value_ptr = NULL;
Sean Callananba992c52010-07-27 02:07:53 +0000665
Sean Callananf5857a02010-07-31 01:32:05 +0000666 if (fun_decl)
Sean Callananba992c52010-07-27 02:07:53 +0000667 {
Sean Callananf5857a02010-07-31 01:32:05 +0000668 if (!m_decl_map->GetFunctionInfo(fun_decl, fun_value_ptr, fun_addr))
669 {
Sean Callanan92aa6662010-09-07 21:49:41 +0000670 fun_value_ptr = NULL;
671
Sean Callananc04743d2010-09-28 21:13:03 +0000672 if (!m_decl_map->GetFunctionAddress(str.c_str(), fun_addr))
Sean Callanan92aa6662010-09-07 21:49:41 +0000673 {
674 if (log)
Sean Callananc04743d2010-09-28 21:13:03 +0000675 log->Printf("Function %s had no address", str.c_str());
Sean Callanan92aa6662010-09-07 21:49:41 +0000676
677 return false;
678 }
Sean Callananf5857a02010-07-31 01:32:05 +0000679 }
680 }
681 else
682 {
Sean Callananc04743d2010-09-28 21:13:03 +0000683 if (!m_decl_map->GetFunctionAddress(str.c_str(), fun_addr))
Sean Callananf5857a02010-07-31 01:32:05 +0000684 {
685 if (log)
Sean Callananc04743d2010-09-28 21:13:03 +0000686 log->Printf("Metadataless function %s had no address", str.c_str());
Sean Callananf5857a02010-07-31 01:32:05 +0000687 }
Sean Callananba992c52010-07-27 02:07:53 +0000688 }
689
690 if (log)
Sean Callananc04743d2010-09-28 21:13:03 +0000691 log->Printf("Found %s at %llx", str.c_str(), fun_addr);
Sean Callananba992c52010-07-27 02:07:53 +0000692
Sean Callananf5857a02010-07-31 01:32:05 +0000693 Value *fun_addr_ptr;
694
695 if (!fun_value_ptr || !*fun_value_ptr)
Sean Callanan02fbafa2010-07-27 21:39:39 +0000696 {
Sean Callanan02fbafa2010-07-27 21:39:39 +0000697 const IntegerType *intptr_ty = Type::getIntNTy(M.getContext(),
698 (M.getPointerSize() == Module::Pointer64) ? 64 : 32);
Sean Callanan92aa6662010-09-07 21:49:41 +0000699 const FunctionType *fun_ty = fun->getFunctionType();
Sean Callanan02fbafa2010-07-27 21:39:39 +0000700 PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
701 Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
Sean Callananf5857a02010-07-31 01:32:05 +0000702 fun_addr_ptr = ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
703
704 if (fun_value_ptr)
705 *fun_value_ptr = fun_addr_ptr;
Sean Callanan02fbafa2010-07-27 21:39:39 +0000706 }
Sean Callananf5857a02010-07-31 01:32:05 +0000707
708 if (fun_value_ptr)
709 fun_addr_ptr = *fun_value_ptr;
Sean Callanan02fbafa2010-07-27 21:39:39 +0000710
Sean Callananf5857a02010-07-31 01:32:05 +0000711 C->setCalledFunction(fun_addr_ptr);
Sean Callanan02fbafa2010-07-27 21:39:39 +0000712
Sean Callananc04743d2010-09-28 21:13:03 +0000713 ConstantArray *func_name = (ConstantArray*)ConstantArray::get(M.getContext(), str);
Sean Callanane8a59a82010-09-13 21:34:21 +0000714
715 Value *values[1];
716 values[0] = func_name;
717 MDNode *func_metadata = MDNode::get(M.getContext(), values, 1);
718
719 C->setMetadata("lldb.call.realName", func_metadata);
720
721 if (log)
722 log->Printf("Set metadata for %p [%d, %s]", C, func_name->isString(), func_name->getAsString().c_str());
723
Sean Callananba992c52010-07-27 02:07:53 +0000724 return true;
725}
726
727bool
Sean Callananf5857a02010-07-31 01:32:05 +0000728IRForTarget::resolveExternals(Module &M, BasicBlock &BB)
Sean Callanan8bce6652010-07-13 21:41:46 +0000729{
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000730 /////////////////////////////////////////////////////////////////////////
731 // Prepare the current basic block for execution in the remote process
732 //
733
Sean Callanan02fbafa2010-07-27 21:39:39 +0000734 BasicBlock::iterator ii;
Sean Callanan8bce6652010-07-13 21:41:46 +0000735
736 for (ii = BB.begin();
737 ii != BB.end();
738 ++ii)
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000739 {
Sean Callanan8bce6652010-07-13 21:41:46 +0000740 Instruction &inst = *ii;
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000741
Sean Callanane8a59a82010-09-13 21:34:21 +0000742 if (m_resolve_vars)
743 {
744 if (LoadInst *load = dyn_cast<LoadInst>(&inst))
745 if (!MaybeHandleVariable(M, load->getPointerOperand(), false))
746 return false;
Sean Callananf5857a02010-07-31 01:32:05 +0000747
Sean Callanane8a59a82010-09-13 21:34:21 +0000748 if (StoreInst *store = dyn_cast<StoreInst>(&inst))
749 if (!MaybeHandleVariable(M, store->getPointerOperand(), true))
750 return false;
751 }
Sean Callananba992c52010-07-27 02:07:53 +0000752
753 if (CallInst *call = dyn_cast<CallInst>(&inst))
754 if (!MaybeHandleCall(M, call))
Sean Callanan8bce6652010-07-13 21:41:46 +0000755 return false;
Sean Callanan5cf4a1c2010-07-03 01:35:46 +0000756 }
757
758 return true;
759}
760
Sean Callanan02fbafa2010-07-27 21:39:39 +0000761static bool isGuardVariableRef(Value *V)
Sean Callanan45839272010-07-24 01:37:44 +0000762{
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000763 Constant *C;
Sean Callanan45839272010-07-24 01:37:44 +0000764
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000765 if (!(C = dyn_cast<Constant>(V)))
Sean Callanan45839272010-07-24 01:37:44 +0000766 return false;
767
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000768 ConstantExpr *CE;
769
770 if ((CE = dyn_cast<ConstantExpr>(V)))
771 {
772 if (CE->getOpcode() != Instruction::BitCast)
773 return false;
774
775 C = CE->getOperand(0);
776 }
777
778 GlobalVariable *GV = dyn_cast<GlobalVariable>(C);
Sean Callanan45839272010-07-24 01:37:44 +0000779
780 if (!GV || !GV->hasName() || !GV->getName().startswith("_ZGV"))
781 return false;
782
783 return true;
784}
785
786static void TurnGuardLoadIntoZero(Instruction* guard_load, Module &M)
787{
788 Constant* zero(ConstantInt::get(Type::getInt8Ty(M.getContext()), 0, true));
789
790 Value::use_iterator ui;
791
792 for (ui = guard_load->use_begin();
793 ui != guard_load->use_end();
794 ++ui)
Sean Callananb5b749c2010-07-27 01:17:28 +0000795 {
Greg Clayton6e713402010-07-30 20:30:44 +0000796 if (isa<Constant>(*ui))
Sean Callananb5b749c2010-07-27 01:17:28 +0000797 {
798 // do nothing for the moment
799 }
800 else
801 {
802 ui->replaceUsesOfWith(guard_load, zero);
803 }
804 }
Sean Callanan45839272010-07-24 01:37:44 +0000805
806 guard_load->eraseFromParent();
807}
808
809static void ExciseGuardStore(Instruction* guard_store)
810{
811 guard_store->eraseFromParent();
812}
813
814bool
815IRForTarget::removeGuards(Module &M, BasicBlock &BB)
816{
817 ///////////////////////////////////////////////////////
818 // Eliminate any reference to guard variables found.
819 //
820
Sean Callanan02fbafa2010-07-27 21:39:39 +0000821 BasicBlock::iterator ii;
Sean Callanan45839272010-07-24 01:37:44 +0000822
Sean Callanan02fbafa2010-07-27 21:39:39 +0000823 typedef SmallVector <Instruction*, 2> InstrList;
Sean Callanan45839272010-07-24 01:37:44 +0000824 typedef InstrList::iterator InstrIterator;
825
826 InstrList guard_loads;
827 InstrList guard_stores;
828
829 for (ii = BB.begin();
830 ii != BB.end();
831 ++ii)
832 {
833 Instruction &inst = *ii;
834
835 if (LoadInst *load = dyn_cast<LoadInst>(&inst))
836 if (isGuardVariableRef(load->getPointerOperand()))
837 guard_loads.push_back(&inst);
838
839 if (StoreInst *store = dyn_cast<StoreInst>(&inst))
840 if (isGuardVariableRef(store->getPointerOperand()))
841 guard_stores.push_back(&inst);
842 }
843
844 InstrIterator iter;
845
846 for (iter = guard_loads.begin();
847 iter != guard_loads.end();
848 ++iter)
849 TurnGuardLoadIntoZero(*iter, M);
850
851 for (iter = guard_stores.begin();
852 iter != guard_stores.end();
853 ++iter)
854 ExciseGuardStore(*iter);
855
856 return true;
857}
858
Sean Callananbafd6852010-07-14 23:40:29 +0000859// UnfoldConstant operates on a constant [C] which has just been replaced with a value
860// [new_value]. We assume that new_value has been properly placed early in the function,
861// most likely somewhere in front of the first instruction in the entry basic block
862// [first_entry_instruction].
863//
864// UnfoldConstant reads through the uses of C and replaces C in those uses with new_value.
865// Where those uses are constants, the function generates new instructions to compute the
866// result of the new, non-constant expression and places them before first_entry_instruction.
867// These instructions replace the constant uses, so UnfoldConstant calls itself recursively
868// for those.
869
870static bool
Sean Callanan02fbafa2010-07-27 21:39:39 +0000871UnfoldConstant(Constant *C, Value *new_value, Instruction *first_entry_instruction)
Sean Callananbafd6852010-07-14 23:40:29 +0000872{
873 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
874
875 Value::use_iterator ui;
876
Sean Callanana48fe162010-08-11 03:57:18 +0000877 SmallVector<User*, 16> users;
878
879 // We do this because the use list might change, invalidating our iterator.
880 // Much better to keep a work list ourselves.
Sean Callananbafd6852010-07-14 23:40:29 +0000881 for (ui = C->use_begin();
882 ui != C->use_end();
883 ++ui)
Sean Callanana48fe162010-08-11 03:57:18 +0000884 users.push_back(*ui);
Sean Callananbafd6852010-07-14 23:40:29 +0000885
Sean Callanana48fe162010-08-11 03:57:18 +0000886 for (int i = 0;
887 i < users.size();
888 ++i)
889 {
890 User *user = users[i];
891
Sean Callananbafd6852010-07-14 23:40:29 +0000892 if (Constant *constant = dyn_cast<Constant>(user))
893 {
894 // synthesize a new non-constant equivalent of the constant
895
896 if (ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(constant))
897 {
898 switch (constant_expr->getOpcode())
899 {
900 default:
901 if (log)
902 log->Printf("Unhandled constant expression type: %s", PrintValue(constant_expr).c_str());
903 return false;
904 case Instruction::BitCast:
905 {
906 // UnaryExpr
907 // OperandList[0] is value
908
909 Value *s = constant_expr->getOperand(0);
910
911 if (s == C)
912 s = new_value;
913
914 BitCastInst *bit_cast(new BitCastInst(s, C->getType(), "", first_entry_instruction));
915
916 UnfoldConstant(constant_expr, bit_cast, first_entry_instruction);
917 }
918 break;
919 case Instruction::GetElementPtr:
920 {
921 // GetElementPtrConstantExpr
922 // OperandList[0] is base
923 // OperandList[1]... are indices
924
925 Value *ptr = constant_expr->getOperand(0);
926
927 if (ptr == C)
928 ptr = new_value;
929
930 SmallVector<Value*, 16> indices;
931
932 unsigned operand_index;
933 unsigned num_operands = constant_expr->getNumOperands();
934
935 for (operand_index = 1;
936 operand_index < num_operands;
937 ++operand_index)
938 {
939 Value *operand = constant_expr->getOperand(operand_index);
940
941 if (operand == C)
942 operand = new_value;
943
944 indices.push_back(operand);
945 }
946
947 GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices.begin(), indices.end(), "", first_entry_instruction));
948
949 UnfoldConstant(constant_expr, get_element_ptr, first_entry_instruction);
950 }
951 break;
952 }
953 }
954 else
955 {
956 if (log)
957 log->Printf("Unhandled constant type: %s", PrintValue(constant).c_str());
958 return false;
959 }
960 }
961 else
962 {
963 // simple fall-through case for non-constants
964 user->replaceUsesOfWith(C, new_value);
965 }
966 }
967
968 return true;
969}
970
Sean Callanan8bce6652010-07-13 21:41:46 +0000971bool
Sean Callananf5857a02010-07-31 01:32:05 +0000972IRForTarget::replaceVariables(Module &M, Function &F)
Sean Callanan8bce6652010-07-13 21:41:46 +0000973{
Sean Callanane8a59a82010-09-13 21:34:21 +0000974 if (!m_resolve_vars)
975 return true;
976
Sean Callanan8bce6652010-07-13 21:41:46 +0000977 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
978
979 m_decl_map->DoStructLayout();
980
981 if (log)
982 log->Printf("Element arrangement:");
983
984 uint32_t num_elements;
985 uint32_t element_index;
986
987 size_t size;
988 off_t alignment;
989
990 if (!m_decl_map->GetStructInfo (num_elements, size, alignment))
991 return false;
992
Sean Callananf5857a02010-07-31 01:32:05 +0000993 Function::arg_iterator iter(F.getArgumentList().begin());
Sean Callanan8bce6652010-07-13 21:41:46 +0000994
Sean Callananf5857a02010-07-31 01:32:05 +0000995 if (iter == F.getArgumentList().end())
Sean Callanan8bce6652010-07-13 21:41:46 +0000996 return false;
997
Sean Callanan02fbafa2010-07-27 21:39:39 +0000998 Argument *argument = iter;
Sean Callanan8bce6652010-07-13 21:41:46 +0000999
Sean Callanan3c9c5eb2010-09-21 00:44:12 +00001000 if (argument->getName().equals("this"))
1001 {
1002 ++iter;
1003
1004 if (iter == F.getArgumentList().end())
1005 return false;
1006
1007 argument = iter;
1008 }
1009
Sean Callanan8bce6652010-07-13 21:41:46 +00001010 if (!argument->getName().equals("___clang_arg"))
1011 return false;
1012
1013 if (log)
1014 log->Printf("Arg: %s", PrintValue(argument).c_str());
1015
Sean Callananf5857a02010-07-31 01:32:05 +00001016 BasicBlock &entry_block(F.getEntryBlock());
Sean Callanan02fbafa2010-07-27 21:39:39 +00001017 Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
Sean Callanan8bce6652010-07-13 21:41:46 +00001018
1019 if (!first_entry_instruction)
1020 return false;
1021
1022 LLVMContext &context(M.getContext());
1023 const IntegerType *offset_type(Type::getInt32Ty(context));
1024
1025 if (!offset_type)
1026 return false;
1027
1028 for (element_index = 0; element_index < num_elements; ++element_index)
1029 {
1030 const clang::NamedDecl *decl;
Sean Callanan02fbafa2010-07-27 21:39:39 +00001031 Value *value;
Sean Callanan8bce6652010-07-13 21:41:46 +00001032 off_t offset;
Sean Callanan45690fe2010-08-30 22:17:16 +00001033 const char *name;
Sean Callanan8bce6652010-07-13 21:41:46 +00001034
Sean Callanan45690fe2010-08-30 22:17:16 +00001035 if (!m_decl_map->GetStructElement (decl, value, offset, name, element_index))
Sean Callanan8bce6652010-07-13 21:41:46 +00001036 return false;
1037
1038 if (log)
Sean Callanan45690fe2010-08-30 22:17:16 +00001039 log->Printf(" %s [%s] (%s) placed at %d",
Sean Callanan82b74c82010-08-12 01:56:52 +00001040 value->getName().str().c_str(),
Sean Callanan45690fe2010-08-30 22:17:16 +00001041 name,
Sean Callanan8bce6652010-07-13 21:41:46 +00001042 PrintValue(value, true).c_str(),
1043 offset);
1044
1045 ConstantInt *offset_int(ConstantInt::getSigned(offset_type, offset));
1046 GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", first_entry_instruction);
1047 BitCastInst *bit_cast = new BitCastInst(get_element_ptr, value->getType(), "", first_entry_instruction);
1048
Sean Callananbafd6852010-07-14 23:40:29 +00001049 if (Constant *constant = dyn_cast<Constant>(value))
1050 UnfoldConstant(constant, bit_cast, first_entry_instruction);
1051 else
1052 value->replaceAllUsesWith(bit_cast);
Sean Callanan8bce6652010-07-13 21:41:46 +00001053 }
1054
1055 if (log)
1056 log->Printf("Total structure [align %d, size %d]", alignment, size);
1057
1058 return true;
1059}
1060
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001061bool
1062IRForTarget::runOnModule(Module &M)
1063{
1064 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
1065
Sean Callanan65dafa82010-08-27 01:01:44 +00001066 Function* function = M.getFunction(StringRef(m_func_name.c_str()));
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001067
1068 if (!function)
1069 {
1070 if (log)
Sean Callanan65dafa82010-08-27 01:01:44 +00001071 log->Printf("Couldn't find %s() in the module", m_func_name.c_str());
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001072
1073 return false;
1074 }
1075
Sean Callanan02fbafa2010-07-27 21:39:39 +00001076 Function::iterator bbi;
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001077
Sean Callanan82b74c82010-08-12 01:56:52 +00001078 ////////////////////////////////////////////////////////////
1079 // Replace __clang_expr_result with a persistent variable
1080 //
1081
1082 if (!createResultVariable(M, *function))
1083 return false;
1084
Sean Callananf5857a02010-07-31 01:32:05 +00001085 //////////////////////////////////
1086 // Run basic-block level passes
1087 //
1088
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001089 for (bbi = function->begin();
1090 bbi != function->end();
1091 ++bbi)
1092 {
Sean Callanan8c127202010-08-23 23:09:38 +00001093 if (!removeGuards(M, *bbi))
1094 return false;
1095
Sean Callanana48fe162010-08-11 03:57:18 +00001096 if (!rewritePersistentAllocs(M, *bbi))
Sean Callananf5857a02010-07-31 01:32:05 +00001097 return false;
1098
Sean Callanana48fe162010-08-11 03:57:18 +00001099 if (!rewriteObjCSelectors(M, *bbi))
1100 return false;
1101
Sean Callananf5857a02010-07-31 01:32:05 +00001102 if (!resolveExternals(M, *bbi))
Sean Callanan8bce6652010-07-13 21:41:46 +00001103 return false;
1104 }
1105
Sean Callanan8bce6652010-07-13 21:41:46 +00001106 if (log)
1107 {
Sean Callanan321fe9e2010-07-28 01:00:59 +00001108 std::string s;
1109 raw_string_ostream oss(s);
Sean Callanan8bce6652010-07-13 21:41:46 +00001110
Sean Callanan321fe9e2010-07-28 01:00:59 +00001111 M.print(oss, NULL);
1112
1113 oss.flush();
1114
1115 log->Printf("Module after preparing for execution: \n%s", s.c_str());
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001116 }
1117
Sean Callanana48fe162010-08-11 03:57:18 +00001118 ///////////////////////////////
1119 // Run function-level passes
1120 //
1121
1122 if (!replaceVariables(M, *function))
1123 return false;
1124
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001125 return true;
1126}
1127
1128void
1129IRForTarget::assignPassManager(PMStack &PMS,
Sean Callanan8bce6652010-07-13 21:41:46 +00001130 PassManagerType T)
Sean Callanan5cf4a1c2010-07-03 01:35:46 +00001131{
1132}
1133
1134PassManagerType
1135IRForTarget::getPotentialPassManagerType() const
1136{
1137 return PMT_ModulePassManager;
1138}