blob: 5c753c506c09adcd169a610c0f401c1557d67f4e [file] [log] [blame]
Chris Lattner59cd9f12001-11-04 23:24:06 +00001//===-- TransformInternals.h - Shared functions for Transforms ---*- C++ -*--=//
2//
3// This header file declares shared functions used by the different components
4// of the Transforms library.
5//
6//===----------------------------------------------------------------------===//
7
8#ifndef TRANSFORM_INTERNALS_H
9#define TRANSFORM_INTERNALS_H
10
11#include "llvm/BasicBlock.h"
Chris Lattnere4f4d8c2001-11-05 18:30:53 +000012#include "llvm/Instruction.h"
Chris Lattner59cd9f12001-11-04 23:24:06 +000013#include "llvm/Target/TargetData.h"
14#include <map>
Chris Lattnere4f4d8c2001-11-05 18:30:53 +000015#include <set>
Chris Lattner59cd9f12001-11-04 23:24:06 +000016
17// TargetData Hack: Eventually we will have annotations given to us by the
18// backend so that we know stuff about type size and alignments. For now
19// though, just use this, because it happens to match the model that GCC uses.
20//
21// FIXME: This should use annotations
22//
23extern const TargetData TD;
24
25// losslessCastableTypes - Return true if the types are bitwise equivalent.
26// This predicate returns true if it is possible to cast from one type to
27// another without gaining or losing precision, or altering the bits in any way.
28//
29bool losslessCastableTypes(const Type *T1, const Type *T2);
30
31
32// ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
33// with a value, then remove and delete the original instruction.
34//
35void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
36 BasicBlock::iterator &BI, Value *V);
37
38// ReplaceInstWithInst - Replace the instruction specified by BI with the
39// instruction specified by I. The original instruction is deleted and BI is
40// updated to point to the new instruction.
41//
42void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
43 BasicBlock::iterator &BI, Instruction *I);
44
45
46// ------------- Expression Conversion ---------------------
47
Chris Lattnere4f4d8c2001-11-05 18:30:53 +000048typedef map<const Value*, const Type*> ValueTypeCache;
49
50struct ValueMapCache {
51 // Operands mapped - Contains an entry if the first value (the user) has had
52 // the second value (the operand) mapped already.
53 //
54 set<pair<const User*, const Value*> > OperandsMapped;
55
56 // Expression Map - Contains an entry from the old value to the new value of
57 // an expression that has been converted over.
58 //
59 map<const Value *, Value *> ExprMap;
60 typedef map<const Value *, Value *> ExprMapTy;
61};
Chris Lattner59cd9f12001-11-04 23:24:06 +000062
63// RetValConvertableToType - Return true if it is possible
64bool RetValConvertableToType(Value *V, const Type *Ty,
65 ValueTypeCache &ConvertedTypes);
66
67void ConvertUsersType(Value *V, Value *NewVal, ValueMapCache &VMC);
68
69
Chris Lattnere4f4d8c2001-11-05 18:30:53 +000070//===----------------------------------------------------------------------===//
71// ValueHandle Class - Smart pointer that occupies a slot on the users USE list
72// that prevents it from being destroyed. This "looks" like an Instruction
73// with Opcode UserOp1.
74//
75class ValueHandle : public Instruction {
76 ValueHandle(const ValueHandle &); // DO NOT IMPLEMENT
77public:
78 ValueHandle(Value *V) : Instruction(Type::VoidTy, UserOp1, "") {
79 Operands.push_back(Use(V, this));
80 }
81
82 ~ValueHandle();
83
84 virtual Instruction *clone() const { abort(); return 0; }
85
86 virtual const char *getOpcodeName() const {
87 return "ValueHandle";
88 }
89
90 // Methods for support type inquiry through isa, cast, and dyn_cast:
91 static inline bool classof(const ValueHandle *) { return true; }
92 static inline bool classof(const Instruction *I) {
93 return (I->getOpcode() == Instruction::UserOp1);
94 }
95 static inline bool classof(const Value *V) {
96 return isa<Instruction>(V) && classof(cast<Instruction>(V));
97 }
98};
99
Chris Lattner59cd9f12001-11-04 23:24:06 +0000100#endif