blob: ac8ec2086b18f58d42d204c4ac23f9faa020840d [file] [log] [blame]
Jim Laskey4556ce52006-03-23 18:05:12 +00001//===-- InstrinsicInst.cpp - Intrinsic Instruction Wrappers -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey4556ce52006-03-23 18:05:12 +00007//
8//===----------------------------------------------------------------------===//
Jim Laskey98a69792006-03-24 10:00:56 +00009//
10// This file implements methods that make it really easy to deal with intrinsic
Devang Patel44a29e02010-01-05 01:10:40 +000011// functions.
Jim Laskey98a69792006-03-24 10:00:56 +000012//
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 Laskey4556ce52006-03-23 18:05:12 +000023
24#include "llvm/IntrinsicInst.h"
Jim Laskey4556ce52006-03-23 18:05:12 +000025#include "llvm/Constants.h"
26#include "llvm/GlobalVariable.h"
Chris Lattner53d00242010-03-14 01:56:06 +000027#include "llvm/Metadata.h"
Jim Laskey4556ce52006-03-23 18:05:12 +000028using namespace llvm;
29
30//===----------------------------------------------------------------------===//
31/// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
32///
33
34static Value *CastOperand(Value *C) {
35 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
Reid Spencer3da59db2006-11-27 01:05:10 +000036 if (CE->isCast())
Jim Laskey4556ce52006-03-23 18:05:12 +000037 return CE->getOperand(0);
38 return NULL;
39}
40
41Value *DbgInfoIntrinsic::StripCast(Value *C) {
42 if (Value *CO = CastOperand(C)) {
Jim Laskeyfbcf23c2006-03-26 22:46:27 +000043 C = StripCast(CO);
Jim Laskey4556ce52006-03-23 18:05:12 +000044 } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
45 if (GV->hasInitializer())
46 if (Value *CO = CastOperand(GV->getInitializer()))
Jim Laskeyfbcf23c2006-03-26 22:46:27 +000047 C = StripCast(CO);
Jim Laskey4556ce52006-03-23 18:05:12 +000048 }
Jim Laskeyfbcf23c2006-03-26 22:46:27 +000049 return dyn_cast<GlobalVariable>(C);
Jim Laskey4556ce52006-03-23 18:05:12 +000050}
51
52//===----------------------------------------------------------------------===//
Victor Hernandez3a328652010-01-15 19:04:09 +000053/// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
54///
55
56Value *DbgDeclareInst::getAddress() const {
Gabor Greif07f639f2010-06-22 19:46:37 +000057 if (MDNode* MD = cast_or_null<MDNode>(getArgOperand(0)))
Victor Hernandez3a328652010-01-15 19:04:09 +000058 return MD->getOperand(0);
59 else
60 return NULL;
61}
62
63//===----------------------------------------------------------------------===//
Chris Lattner183912a2009-12-31 01:32:41 +000064/// DbgValueInst - This represents the llvm.dbg.value instruction.
65///
66
Victor Hernandez5b7e48b2010-01-11 07:45:19 +000067const Value *DbgValueInst::getValue() const {
Gabor Greif07f639f2010-06-22 19:46:37 +000068 return cast<MDNode>(getArgOperand(0))->getOperand(0);
Victor Hernandez5b7e48b2010-01-11 07:45:19 +000069}
70
71Value *DbgValueInst::getValue() {
Gabor Greif07f639f2010-06-22 19:46:37 +000072 return cast<MDNode>(getArgOperand(0))->getOperand(0);
Chris Lattner183912a2009-12-31 01:32:41 +000073}