106 using namespace llvm;
108 #define DEBUG_TYPE "mergefunc"
110 STATISTIC(NumFunctionsMerged,
"Number of functions merged");
111 STATISTIC(NumThunksWritten,
"Number of thunks generated");
112 STATISTIC(NumAliasesWritten,
"Number of aliases generated");
113 STATISTIC(NumDoubleWeak,
"Number of new functions created");
117 cl::desc(
"How many functions in module could be used for "
118 "MergeFunctions pass sanity check. "
119 "'0' disables this check. Works only with '-debug' key."),
128 class FunctionComparator {
131 : FnL(F1), FnR(F2) {}
262 int cmpValues(
const Value *L,
const Value *R);
300 return cmpGEPs(cast<GEPOperator>(GEPL), cast<GEPOperator>(GEPR));
343 int cmpTypes(
Type *TyL,
Type *TyR)
const;
345 int cmpNumbers(uint64_t L, uint64_t R)
const;
347 int cmpAPInts(
const APInt &L,
const APInt &R)
const;
401 assert(!(*
this < FunctionNode(G)) && !(FunctionNode(G) < *
this) &&
402 "The two functions must be equal");
407 void release() {
F = 0; }
408 bool operator<(
const FunctionNode &RHS)
const {
409 return (FunctionComparator(
F, RHS.getFunc()).
compare()) == -1;
414 int FunctionComparator::cmpNumbers(uint64_t L, uint64_t R)
const {
415 if (L < R)
return -1;
420 int FunctionComparator::cmpAPInts(
const APInt &L,
const APInt &R)
const {
423 if (L.
ugt(R))
return 1;
424 if (R.
ugt(L))
return -1;
428 int FunctionComparator::cmpAPFloats(
const APFloat &L,
const APFloat &R)
const {
437 if (
int Res = cmpNumbers(L.
size(), R.
size()))
450 for (
unsigned i = 0, e = L.
getNumSlots(); i != e; ++i) {
453 for (; LI !=
LE && RI != RE; ++LI, ++RI) {
474 int FunctionComparator::cmpConstants(
const Constant *L,
const Constant *R) {
482 int TypesRes = cmpTypes(TyL, TyR);
500 unsigned TyLWidth = 0;
501 unsigned TyRWidth = 0;
503 if (
const VectorType *VecTyL = dyn_cast<VectorType>(TyL))
504 TyLWidth = VecTyL->getBitWidth();
505 if (
const VectorType *VecTyR = dyn_cast<VectorType>(TyR))
506 TyRWidth = VecTyR->getBitWidth();
508 if (TyLWidth != TyRWidth)
509 return cmpNumbers(TyLWidth, TyRWidth);
517 unsigned AddrSpaceR = PTyR->getAddressSpace();
518 if (
int Res = cmpNumbers(AddrSpaceL, AddrSpaceR))
545 case Value::UndefValueVal:
return TypesRes;
546 case Value::ConstantIntVal: {
547 const APInt &LInt = cast<ConstantInt>(L)->getValue();
548 const APInt &RInt = cast<ConstantInt>(R)->getValue();
549 return cmpAPInts(LInt, RInt);
551 case Value::ConstantFPVal: {
552 const APFloat &LAPF = cast<ConstantFP>(L)->getValueAPF();
553 const APFloat &RAPF = cast<ConstantFP>(R)->getValueAPF();
554 return cmpAPFloats(LAPF, RAPF);
556 case Value::ConstantArrayVal: {
559 uint64_t NumElementsL = cast<ArrayType>(TyL)->getNumElements();
560 uint64_t NumElementsR = cast<ArrayType>(TyR)->getNumElements();
561 if (
int Res = cmpNumbers(NumElementsL, NumElementsR))
563 for (uint64_t i = 0; i < NumElementsL; ++i) {
564 if (
int Res = cmpConstants(cast<Constant>(LA->
getOperand(i)),
565 cast<Constant>(RA->getOperand(i))))
570 case Value::ConstantStructVal: {
573 unsigned NumElementsL = cast<StructType>(TyL)->getNumElements();
574 unsigned NumElementsR = cast<StructType>(TyR)->getNumElements();
575 if (
int Res = cmpNumbers(NumElementsL, NumElementsR))
577 for (
unsigned i = 0; i != NumElementsL; ++i) {
578 if (
int Res = cmpConstants(cast<Constant>(LS->
getOperand(i)),
579 cast<Constant>(RS->getOperand(i))))
584 case Value::ConstantVectorVal: {
587 unsigned NumElementsL = cast<VectorType>(TyL)->getNumElements();
588 unsigned NumElementsR = cast<VectorType>(TyR)->getNumElements();
589 if (
int Res = cmpNumbers(NumElementsL, NumElementsR))
591 for (uint64_t i = 0; i < NumElementsL; ++i) {
592 if (
int Res = cmpConstants(cast<Constant>(LV->
getOperand(i)),
593 cast<Constant>(RV->getOperand(i))))
598 case Value::ConstantExprVal: {
602 unsigned NumOperandsR = RE->getNumOperands();
603 if (
int Res = cmpNumbers(NumOperandsL, NumOperandsR))
605 for (
unsigned i = 0; i < NumOperandsL; ++i) {
606 if (
int Res = cmpConstants(cast<Constant>(LE->
getOperand(i)),
607 cast<Constant>(RE->getOperand(i))))
612 case Value::FunctionVal:
613 case Value::GlobalVariableVal:
614 case Value::GlobalAliasVal:
616 return cmpNumbers((uint64_t)L, (uint64_t)R);
623 int FunctionComparator::cmpTypes(
Type *TyL,
Type *TyR)
const {
628 const DataLayout &
DL = FnL->getParent()->getDataLayout();
630 TyL = DL.getIntPtrType(TyL);
631 if (PTyR && PTyR->getAddressSpace() == 0)
632 TyR = DL.getIntPtrType(TyR);
647 return cmpNumbers((uint64_t)TyL, (uint64_t)TyR);
660 assert(PTyL && PTyR &&
"Both types must be pointers here.");
668 return cmpNumbers(STyL->
getNumElements(), STyR->getNumElements());
670 if (STyL->
isPacked() != STyR->isPacked())
671 return cmpNumbers(STyL->
isPacked(), STyR->isPacked());
674 if (
int Res = cmpTypes(STyL->
getElementType(i), STyR->getElementType(i)))
684 return cmpNumbers(FTyL->
getNumParams(), FTyR->getNumParams());
686 if (FTyL->
isVarArg() != FTyR->isVarArg())
687 return cmpNumbers(FTyL->
isVarArg(), FTyR->isVarArg());
689 if (
int Res = cmpTypes(FTyL->
getReturnType(), FTyR->getReturnType()))
692 for (
unsigned i = 0, e = FTyL->
getNumParams(); i != e; ++i) {
693 if (
int Res = cmpTypes(FTyL->
getParamType(i), FTyR->getParamType(i)))
703 return cmpNumbers(ATyL->
getNumElements(), ATyR->getNumElements());
713 int FunctionComparator::cmpOperations(
const Instruction *L,
732 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(L)) {
733 if (
int Res = cmpTypes(AI->getAllocatedType(),
734 cast<AllocaInst>(R)->getAllocatedType()))
737 cmpNumbers(AI->getAlignment(), cast<AllocaInst>(R)->getAlignment()))
750 if (
const LoadInst *LI = dyn_cast<LoadInst>(L)) {
751 if (
int Res = cmpNumbers(LI->isVolatile(), cast<LoadInst>(R)->
isVolatile()))
754 cmpNumbers(LI->
getAlignment(), cast<LoadInst>(R)->getAlignment()))
757 cmpNumbers(LI->getOrdering(), cast<LoadInst>(R)->getOrdering()))
760 cmpNumbers(LI->getSynchScope(), cast<LoadInst>(R)->getSynchScope()))
765 if (
const StoreInst *SI = dyn_cast<StoreInst>(L)) {
767 cmpNumbers(
SI->isVolatile(), cast<StoreInst>(R)->
isVolatile()))
770 cmpNumbers(
SI->getAlignment(), cast<StoreInst>(R)->getAlignment()))
773 cmpNumbers(
SI->getOrdering(), cast<StoreInst>(R)->getOrdering()))
775 return cmpNumbers(
SI->getSynchScope(), cast<StoreInst>(R)->getSynchScope());
777 if (
const CmpInst *CI = dyn_cast<CmpInst>(L))
778 return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
779 if (
const CallInst *CI = dyn_cast<CallInst>(L)) {
780 if (
int Res = cmpNumbers(CI->getCallingConv(),
781 cast<CallInst>(R)->getCallingConv()))
784 cmpAttrs(CI->getAttributes(), cast<CallInst>(R)->
getAttributes()))
790 if (
const InvokeInst *CI = dyn_cast<InvokeInst>(L)) {
791 if (
int Res = cmpNumbers(CI->getCallingConv(),
792 cast<InvokeInst>(R)->getCallingConv()))
795 cmpAttrs(CI->getAttributes(), cast<InvokeInst>(R)->
getAttributes()))
804 if (
int Res = cmpNumbers(LIndices.
size(), RIndices.
size()))
806 for (
size_t i = 0, e = LIndices.
size(); i != e; ++i) {
807 if (
int Res = cmpNumbers(LIndices[i], RIndices[i]))
814 if (
int Res = cmpNumbers(LIndices.
size(), RIndices.
size()))
816 for (
size_t i = 0, e = LIndices.
size(); i != e; ++i) {
817 if (
int Res = cmpNumbers(LIndices[i], RIndices[i]))
821 if (
const FenceInst *FI = dyn_cast<FenceInst>(L)) {
823 cmpNumbers(FI->getOrdering(), cast<FenceInst>(R)->getOrdering()))
825 return cmpNumbers(FI->getSynchScope(), cast<FenceInst>(R)->getSynchScope());
829 if (
int Res = cmpNumbers(CXI->isVolatile(),
832 if (
int Res = cmpNumbers(CXI->isWeak(),
833 cast<AtomicCmpXchgInst>(R)->
isWeak()))
835 if (
int Res = cmpNumbers(CXI->getSuccessOrdering(),
836 cast<AtomicCmpXchgInst>(R)->getSuccessOrdering()))
838 if (
int Res = cmpNumbers(CXI->getFailureOrdering(),
839 cast<AtomicCmpXchgInst>(R)->getFailureOrdering()))
841 return cmpNumbers(CXI->getSynchScope(),
842 cast<AtomicCmpXchgInst>(R)->getSynchScope());
844 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(L)) {
845 if (
int Res = cmpNumbers(RMWI->getOperation(),
846 cast<AtomicRMWInst>(R)->getOperation()))
848 if (
int Res = cmpNumbers(RMWI->isVolatile(),
851 if (
int Res = cmpNumbers(RMWI->getOrdering(),
852 cast<AtomicRMWInst>(R)->getOrdering()))
854 return cmpNumbers(RMWI->getSynchScope(),
855 cast<AtomicRMWInst>(R)->getSynchScope());
862 int FunctionComparator::cmpGEPs(
const GEPOperator *GEPL,
868 if (
int Res = cmpNumbers(ASL, ASR))
873 const DataLayout &DL = FnL->getParent()->getDataLayout();
875 APInt OffsetL(BitWidth, 0), OffsetR(BitWidth, 0);
878 return cmpAPInts(OffsetL, OffsetR);
899 int FunctionComparator::cmpValues(
const Value *L,
const Value *R) {
914 if (ConstL && ConstR) {
917 return cmpConstants(ConstL, ConstR);
928 if (InlineAsmL && InlineAsmR)
929 return cmpNumbers((uint64_t)L, (uint64_t)R);
935 auto LeftSN = sn_mapL.insert(std::make_pair(L, sn_mapL.size())),
936 RightSN = sn_mapR.insert(std::make_pair(R, sn_mapR.size()));
938 return cmpNumbers(LeftSN.first->second, RightSN.first->second);
946 if (
int Res = cmpValues(InstL, InstR))
961 if (
int Res = cmpGEPs(GEPL, GEPR))
964 if (
int Res = cmpOperations(InstL, InstR))
966 assert(InstL->getNumOperands() == InstR->getNumOperands());
968 for (
unsigned i = 0, e = InstL->getNumOperands(); i != e; ++i) {
969 Value *OpL = InstL->getOperand(i);
970 Value *OpR = InstR->getOperand(i);
971 if (
int Res = cmpValues(OpL, OpR))
982 }
while (InstL != InstLE && InstR != InstRE);
984 if (InstL != InstLE && InstR == InstRE)
986 if (InstL == InstLE && InstR != InstRE)
997 if (
int Res = cmpAttrs(FnL->getAttributes(), FnR->getAttributes()))
1000 if (
int Res = cmpNumbers(FnL->hasGC(), FnR->hasGC()))
1004 if (
int Res = cmpNumbers((uint64_t)FnL->getGC(), (uint64_t)FnR->getGC()))
1008 if (
int Res = cmpNumbers(FnL->hasSection(), FnR->hasSection()))
1011 if (FnL->hasSection()) {
1012 if (
int Res = cmpStrings(FnL->getSection(), FnR->getSection()))
1016 if (
int Res = cmpNumbers(FnL->isVarArg(), FnR->isVarArg()))
1021 if (
int Res = cmpNumbers(FnL->getCallingConv(), FnR->getCallingConv()))
1024 if (
int Res = cmpTypes(FnL->getFunctionType(), FnR->getFunctionType()))
1027 assert(FnL->arg_size() == FnR->arg_size() &&
1028 "Identically typed functions have different numbers of args!");
1033 ArgRI = FnR->arg_begin(),
1034 ArgLE = FnL->arg_end();
1035 ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
1036 if (cmpValues(ArgLI, ArgRI) != 0)
1047 FnLBBs.
push_back(&FnL->getEntryBlock());
1048 FnRBBs.
push_back(&FnR->getEntryBlock());
1050 VisitedBBs.
insert(FnLBBs[0]);
1051 while (!FnLBBs.
empty()) {
1055 if (
int Res = cmpValues(BBL, BBR))
1058 if (
int Res =
compare(BBL, BBR))
1091 bool runOnModule(
Module &M)
override;
1094 typedef std::set<FunctionNode> FnTreeType;
1098 std::vector<WeakVH> Deferred;
1102 bool doSanityCheck(std::vector<WeakVH> &Worklist);
1106 bool insert(
Function *NewFunction);
1114 void removeUsers(
Value *V);
1136 void replaceFunctionInTree(FnTreeType::iterator &IterToF,
Function *G);
1143 bool HasGlobalAliases;
1149 INITIALIZE_PASS(MergeFunctions,
"mergefunc",
"Merge Functions",
false,
false)
1152 return new MergeFunctions();
1155 bool MergeFunctions::doSanityCheck(std::vector<WeakVH> &Worklist) {
1157 unsigned TripleNumber = 0;
1160 dbgs() <<
"MERGEFUNC-SANITY: Started for first " <<
Max <<
" functions.\n";
1163 for (std::vector<WeakVH>::iterator
I = Worklist.begin(), E = Worklist.end();
1164 I != E && i <
Max; ++
I, ++i) {
1166 for (std::vector<WeakVH>::iterator J =
I; J != E && j < Max; ++J, ++j) {
1169 int Res1 = FunctionComparator(F1, F2).compare();
1170 int Res2 = FunctionComparator(F2, F1).compare();
1173 if (Res1 != -Res2) {
1174 dbgs() <<
"MERGEFUNC-SANITY: Non-symmetric; triple: " << TripleNumber
1185 for (std::vector<WeakVH>::iterator K = J; K != E && k < Max;
1186 ++k, ++K, ++TripleNumber) {
1191 int Res3 = FunctionComparator(F1, F3).compare();
1192 int Res4 = FunctionComparator(F2, F3).compare();
1194 bool Transitive =
true;
1196 if (Res1 != 0 && Res1 == Res4) {
1198 Transitive = Res3 == Res1;
1199 }
else if (Res3 != 0 && Res3 == -Res4) {
1201 Transitive = Res3 == Res1;
1202 }
else if (Res4 != 0 && -Res3 == Res4) {
1204 Transitive = Res4 == -Res1;
1208 dbgs() <<
"MERGEFUNC-SANITY: Non-transitive; triple: "
1209 << TripleNumber <<
"\n";
1210 dbgs() <<
"Res1, Res3, Res4: " << Res1 <<
", " << Res3 <<
", "
1221 dbgs() <<
"MERGEFUNC-SANITY: " << (Valid ?
"Passed." :
"Failed.") <<
"\n";
1227 bool MergeFunctions::runOnModule(
Module &M) {
1228 bool Changed =
false;
1231 if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage())
1232 Deferred.push_back(
WeakVH(I));
1236 std::vector<WeakVH> Worklist;
1237 Deferred.swap(Worklist);
1239 DEBUG(doSanityCheck(Worklist));
1242 DEBUG(
dbgs() <<
"size of worklist: " << Worklist.size() <<
'\n');
1246 for (std::vector<WeakVH>::iterator I = Worklist.begin(),
1247 E = Worklist.end(); I != E; ++
I) {
1252 Changed |= insert(F);
1260 for (std::vector<WeakVH>::iterator I = Worklist.begin(),
1261 E = Worklist.end(); I != E; ++
I) {
1266 Changed |= insert(F);
1269 DEBUG(
dbgs() <<
"size of FnTree: " << FnTree.size() <<
'\n');
1270 }
while (!Deferred.empty());
1284 if (CS &&
CS.isCallee(U)) {
1285 remove(
CS.getInstruction()->getParent()->getParent());
1337 replaceDirectCallers(G, F);
1361 CallInst *CI = Builder.CreateCall(F, Args);
1365 Builder.CreateRetVoid();
1391 DEBUG(
dbgs() <<
"writeAlias: " << GA->getName() <<
'\n');
1392 ++NumAliasesWritten;
1408 unsigned MaxAlignment = std::max(G->
getAlignment(), H->getAlignment());
1410 if (HasGlobalAliases) {
1422 writeThunkOrAlias(F, G);
1425 ++NumFunctionsMerged;
1429 void MergeFunctions::replaceFunctionInTree(FnTreeType::iterator &IterToF,
1437 "Only change functions if both are strong or both are weak");
1440 IterToF->replaceBy(G);
1445 bool MergeFunctions::insert(
Function *NewFunction) {
1446 std::pair<FnTreeType::iterator, bool> Result =
1447 FnTree.insert(FunctionNode(NewFunction));
1449 if (Result.second) {
1450 DEBUG(
dbgs() <<
"Inserting as unique: " << NewFunction->
getName() <<
'\n');
1454 const FunctionNode &OldF = *Result.first;
1460 if (NewFunction->
size() == 1) {
1463 <<
" is to small to bother merging\n");
1474 if ((OldF.getFunc()->mayBeOverridden() && NewFunction->
mayBeOverridden()) ||
1475 (!OldF.getFunc()->mayBeOverridden() && !NewFunction->
mayBeOverridden()))
1476 if (OldF.getFunc()->getName() > NewFunction->
getName()) {
1479 replaceFunctionInTree(Result.first, NewFunction);
1481 assert(OldF.getFunc() != F &&
"Must have swapped the functions.");
1485 assert(!OldF.getFunc()->mayBeOverridden() || NewFunction->
mayBeOverridden());
1487 DEBUG(
dbgs() <<
" " << OldF.getFunc()->getName()
1488 <<
" == " << NewFunction->
getName() <<
'\n');
1491 mergeTwoFunctions(OldF.getFunc(), DeleteF);
1500 FnTreeType::iterator found = FnTree.find(FunctionNode(F));
1502 if (found != FnTree.end() && found->getFunc() ==
F) {
1504 FnTree.erase(found);
1509 <<
" from set and deferred it.\n");
1510 Deferred.emplace_back(F);
1516 void MergeFunctions::removeUsers(
Value *V) {
1517 std::vector<Value *> Worklist;
1518 Worklist.push_back(V);
1519 while (!Worklist.empty()) {
1520 Value *V = Worklist.back();
1521 Worklist.pop_back();
1525 remove(I->getParent()->getParent());
1526 }
else if (isa<GlobalValue>(U)) {
1528 }
else if (
Constant *C = dyn_cast<Constant>(U)) {
1529 for (
User *UU :
C->users())
1530 Worklist.push_back(UU);
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
LinkageTypes getLinkage() const
static Value * createCast(IRBuilder< false > &Builder, Value *V, Type *DestTy)
Value * getPointerOperand()
This class is the base class for the comparison instructions.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
VisibilityTypes getVisibility() const
unsigned getStructNumElements() const
STATISTIC(NumFunctions,"Total number of functions")
size_t size() const
size - Get the string size.
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
2: 32-bit floating point type
FenceInst - an instruction for ordering other memory operations.
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
ModulePass * createMergeFunctionsPass()
createMergeFunctionsPass - This pass discovers identical functions and collapses them.
unsigned getNumOperands() const
CallInst - This class represents a function call, abstracting a target machine's calling convention...
Like Internal, but omit from symbol table.
bool hasAvailableExternallyLinkage() const
iterator begin(unsigned Slot) const
Type * getReturnType() const
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
4: 80-bit floating point type (X87)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
LoadInst - an instruction for reading from memory.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
void setAlignment(unsigned Align)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
void setCallingConv(CallingConv::ID CC)
int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
A Use represents the edge between a Value definition and its users.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
FunctionType - Class to represent function types.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Value handle that is nullable, but tries to track the Value.
unsigned getAlignment() const
ArrayType - Class to represent array types.
bool isFirstClassType() const
isFirstClassType - Return true if the type is "first class", meaning it is a valid type for a Value...
TypeID getTypeID() const
getTypeID - Return the type id for the type.
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
void initializeMergeFunctionsPass(PassRegistry &)
Type * getElementType() const
size_t size() const
size - Get the array size.
PointerType - Class to represent pointers.
10: Arbitrary bit width integers
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
Type * getParamType(unsigned i) const
Parameter type accessors.
initializer< Ty > init(const Ty &Val)
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
static bool mayBeOverridden(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
static GlobalAlias * create(PointerType *Ty, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Type * getElementType(unsigned N) const
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
This is an important base class in LLVM.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
uint64_t getNumElements() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getValueID() const
Return an ID for the concrete type of this object.
Value * getPointerOperand()
void copyAttributesFrom(const GlobalValue *Src) override
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
ConstantVector - Constant Vector Declarations.
void setTailCall(bool isTC=true)
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
bool hasWeakLinkage() const
void dump() const
Support for debugging, callable in GDB: V->dump()
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
bool hasExternalLinkage() const
15: SIMD 'packed' format, or other vector type
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
iterator end(unsigned Slot) const
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
Value handle that asserts if the Value is deleted.
void setLinkage(LinkageTypes LT)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
VectorType - Class to represent vector types.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
static bool isWeak(const MCSymbolELF &Sym)
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
APInt bitcastToAPInt() const
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
PointerType * getType() const
Global values are always pointers.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
static cl::opt< unsigned > NumFunctionsForSanityCheck("mergefunc-sanity", cl::desc("How many functions in module could be used for ""MergeFunctions pass sanity check. ""'0' disables this check. Works only with '-debug' key."), cl::init(0), cl::Hidden)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
FunctionType * getFunctionType() const
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
bool hasLocalLinkage() const
int compare(DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
Compare two scaled numbers.
3: 64-bit floating point type
Type * getReturnType() const
const BasicBlock & front() const
bool operator<(int64_t V1, const APSInt &V2)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool hasUnnamedAddr() const
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
InvokeInst - Invoke instruction.
Type * getStructElementType(unsigned N) const
C - The default llvm calling convention, compatible with C.
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
static bool isVolatile(Instruction *Inst)
unsigned getNumElements() const
Random access to the elements.
const fltSemantics & getSemantics() const
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
5: 128-bit floating point type (112-bit mantissa)