Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 1 | //===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jim Laskey | 98a6979 | 2006-03-24 10:00:56 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements methods that make it really easy to deal with intrinsic |
Devang Patel | 44a29e0 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 11 | // functions. |
Jim Laskey | 98a6979 | 2006-03-24 10:00:56 +0000 | [diff] [blame] | 12 | // |
| 13 | // All intrinsic function calls are instances of the call instruction, so these |
| 14 | // are all subclasses of the CallInst class. Note that none of these classes |
| 15 | // has state or virtual methods, which is an important part of this gross/neat |
| 16 | // hack working. |
| 17 | // |
| 18 | // In some cases, arguments to intrinsics need to be generic and are defined as |
| 19 | // type pointer to empty struct { }*. To access the real item of interest the |
| 20 | // cast instruction needs to be stripped away. |
| 21 | // |
| 22 | //===----------------------------------------------------------------------===// |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 23 | |
| 24 | #include "llvm/IntrinsicInst.h" |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" |
| 26 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 53d0024 | 2010-03-14 01:56:06 +0000 | [diff] [blame] | 27 | #include "llvm/Metadata.h" |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics |
| 32 | /// |
| 33 | |
| 34 | static Value *CastOperand(Value *C) { |
| 35 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 36 | if (CE->isCast()) |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 37 | return CE->getOperand(0); |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | Value *DbgInfoIntrinsic::StripCast(Value *C) { |
| 42 | if (Value *CO = CastOperand(C)) { |
Jim Laskey | fbcf23c | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 43 | C = StripCast(CO); |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 44 | } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { |
| 45 | if (GV->hasInitializer()) |
| 46 | if (Value *CO = CastOperand(GV->getInitializer())) |
Jim Laskey | fbcf23c | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 47 | C = StripCast(CO); |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 48 | } |
Jim Laskey | fbcf23c | 2006-03-26 22:46:27 +0000 | [diff] [blame] | 49 | return dyn_cast<GlobalVariable>(C); |
Jim Laskey | 4556ce5 | 2006-03-23 18:05:12 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | //===----------------------------------------------------------------------===// |
Victor Hernandez | 3a32865 | 2010-01-15 19:04:09 +0000 | [diff] [blame] | 53 | /// DbgDeclareInst - This represents the llvm.dbg.declare instruction. |
| 54 | /// |
| 55 | |
| 56 | Value *DbgDeclareInst::getAddress() const { |
Gabor Greif | 07f639f | 2010-06-22 19:46:37 +0000 | [diff] [blame] | 57 | if (MDNode* MD = cast_or_null<MDNode>(getArgOperand(0))) |
Victor Hernandez | 3a32865 | 2010-01-15 19:04:09 +0000 | [diff] [blame] | 58 | return MD->getOperand(0); |
| 59 | else |
| 60 | return NULL; |
| 61 | } |
| 62 | |
| 63 | //===----------------------------------------------------------------------===// |
Chris Lattner | 183912a | 2009-12-31 01:32:41 +0000 | [diff] [blame] | 64 | /// DbgValueInst - This represents the llvm.dbg.value instruction. |
| 65 | /// |
| 66 | |
Victor Hernandez | 5b7e48b | 2010-01-11 07:45:19 +0000 | [diff] [blame] | 67 | const Value *DbgValueInst::getValue() const { |
Gabor Greif | 07f639f | 2010-06-22 19:46:37 +0000 | [diff] [blame] | 68 | return cast<MDNode>(getArgOperand(0))->getOperand(0); |
Victor Hernandez | 5b7e48b | 2010-01-11 07:45:19 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Value *DbgValueInst::getValue() { |
Gabor Greif | 07f639f | 2010-06-22 19:46:37 +0000 | [diff] [blame] | 72 | return cast<MDNode>(getArgOperand(0))->getOperand(0); |
Chris Lattner | 183912a | 2009-12-31 01:32:41 +0000 | [diff] [blame] | 73 | } |