mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
AutoUpgrade: upgrade from scalar TBAA format to struct-path aware TBAA format.
We treat TBAA tags as struct-path aware TBAA format when the first operand is a MDNode and the tag has 3 or more operands. llvm-svn: 191593
This commit is contained in:
parent
e5351a10fe
commit
5124fcbf05
@ -19,6 +19,7 @@ namespace llvm {
|
|||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
class Function;
|
class Function;
|
||||||
class CallInst;
|
class CallInst;
|
||||||
|
class Instruction;
|
||||||
|
|
||||||
/// This is a more granular function that simply checks an intrinsic function
|
/// This is a more granular function that simply checks an intrinsic function
|
||||||
/// for upgrading, and returns true if it requires upgrading. It may return
|
/// for upgrading, and returns true if it requires upgrading. It may return
|
||||||
@ -39,6 +40,10 @@ namespace llvm {
|
|||||||
/// This checks for global variables which should be upgraded. It returns true
|
/// This checks for global variables which should be upgraded. It returns true
|
||||||
/// if it requires upgrading.
|
/// if it requires upgrading.
|
||||||
bool UpgradeGlobalVariable(GlobalVariable *GV);
|
bool UpgradeGlobalVariable(GlobalVariable *GV);
|
||||||
|
|
||||||
|
/// If the TBAA tag for the given instruction uses the scalar TBAA format,
|
||||||
|
/// we upgrade it to the struct-path aware TBAA format.
|
||||||
|
void UpgradeInstWithTBAATag(Instruction *I);
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "llvm/IR/DerivedTypes.h"
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
#include "llvm/IR/InlineAsm.h"
|
#include "llvm/IR/InlineAsm.h"
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/Operator.h"
|
#include "llvm/IR/Operator.h"
|
||||||
#include "llvm/IR/ValueSymbolTable.h"
|
#include "llvm/IR/ValueSymbolTable.h"
|
||||||
@ -65,6 +66,9 @@ bool LLParser::ValidateEndOfModule() {
|
|||||||
ForwardRefInstMetadata.clear();
|
ForwardRefInstMetadata.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++)
|
||||||
|
UpgradeInstWithTBAATag(InstsWithTBAATag[I]);
|
||||||
|
|
||||||
// Handle any function attribute group forward references.
|
// Handle any function attribute group forward references.
|
||||||
for (std::map<Value*, std::vector<unsigned> >::iterator
|
for (std::map<Value*, std::vector<unsigned> >::iterator
|
||||||
I = ForwardRefAttrGroups.begin(), E = ForwardRefAttrGroups.end();
|
I = ForwardRefAttrGroups.begin(), E = ForwardRefAttrGroups.end();
|
||||||
@ -1427,6 +1431,9 @@ bool LLParser::ParseInstructionMetadata(Instruction *Inst,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MDK == LLVMContext::MD_tbaa)
|
||||||
|
InstsWithTBAATag.push_back(Inst);
|
||||||
|
|
||||||
// If this is the end of the list, we're done.
|
// If this is the end of the list, we're done.
|
||||||
} while (EatIfPresent(lltok::comma));
|
} while (EatIfPresent(lltok::comma));
|
||||||
return false;
|
return false;
|
||||||
|
@ -107,6 +107,8 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata;
|
DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata;
|
||||||
|
|
||||||
|
SmallVector<Instruction*, 64> InstsWithTBAATag;
|
||||||
|
|
||||||
// Type resolution handling data structures. The location is set when we
|
// Type resolution handling data structures. The location is set when we
|
||||||
// have processed a use of the type but not a definition yet.
|
// have processed a use of the type but not a definition yet.
|
||||||
StringMap<std::pair<Type*, LocTy> > NamedTypes;
|
StringMap<std::pair<Type*, LocTy> > NamedTypes;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "llvm/IR/DerivedTypes.h"
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
#include "llvm/IR/InlineAsm.h"
|
#include "llvm/IR/InlineAsm.h"
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
#include "llvm/IR/IntrinsicInst.h"
|
||||||
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/OperandTraits.h"
|
#include "llvm/IR/OperandTraits.h"
|
||||||
#include "llvm/IR/Operator.h"
|
#include "llvm/IR/Operator.h"
|
||||||
@ -2123,6 +2124,8 @@ bool BitcodeReader::ParseMetadataAttachment() {
|
|||||||
return Error("Invalid metadata kind ID");
|
return Error("Invalid metadata kind ID");
|
||||||
Value *Node = MDValueList.getValueFwdRef(Record[i+1]);
|
Value *Node = MDValueList.getValueFwdRef(Record[i+1]);
|
||||||
Inst->setMetadata(I->second, cast<MDNode>(Node));
|
Inst->setMetadata(I->second, cast<MDNode>(Node));
|
||||||
|
if (I->second == LLVMContext::MD_tbaa)
|
||||||
|
InstsWithTBAATag.push_back(Inst);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3134,6 +3137,9 @@ bool BitcodeReader::MaterializeModule(Module *M, std::string *ErrInfo) {
|
|||||||
}
|
}
|
||||||
std::vector<std::pair<Function*, Function*> >().swap(UpgradedIntrinsics);
|
std::vector<std::pair<Function*, Function*> >().swap(UpgradedIntrinsics);
|
||||||
|
|
||||||
|
for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++)
|
||||||
|
UpgradeInstWithTBAATag(InstsWithTBAATag[I]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ class BitcodeReader : public GVMaterializer {
|
|||||||
std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
|
std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
|
||||||
std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
|
std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
|
||||||
|
|
||||||
|
SmallVector<Instruction*, 64> InstsWithTBAATag;
|
||||||
|
|
||||||
/// MAttributes - The set of attributes by index. Index zero in the
|
/// MAttributes - The set of attributes by index. Index zero in the
|
||||||
/// file is for null, and is thus not represented here. As such all indices
|
/// file is for null, and is thus not represented here. As such all indices
|
||||||
/// are off by one.
|
/// are off by one.
|
||||||
|
@ -391,3 +391,30 @@ void llvm::UpgradeCallsToIntrinsic(Function* F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void llvm::UpgradeInstWithTBAATag(Instruction *I) {
|
||||||
|
MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa);
|
||||||
|
assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag");
|
||||||
|
// Check if the tag uses struct-path aware TBAA format.
|
||||||
|
if (isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (MD->getNumOperands() == 3) {
|
||||||
|
Value *Elts[] = {
|
||||||
|
MD->getOperand(0),
|
||||||
|
MD->getOperand(1)
|
||||||
|
};
|
||||||
|
MDNode *ScalarType = MDNode::get(I->getContext(), Elts);
|
||||||
|
// Create a MDNode <ScalarType, ScalarType, offset 0, const>
|
||||||
|
Value *Elts2[] = {
|
||||||
|
ScalarType, ScalarType,
|
||||||
|
Constant::getNullValue(Type::getInt64Ty(I->getContext())),
|
||||||
|
MD->getOperand(2)
|
||||||
|
};
|
||||||
|
I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts2));
|
||||||
|
} else {
|
||||||
|
// Create a MDNode <MD, MD, offset 0>
|
||||||
|
Value *Elts[] = {MD, MD,
|
||||||
|
Constant::getNullValue(Type::getInt64Ty(I->getContext()))};
|
||||||
|
I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
23
test/Bitcode/upgrade-tbaa.ll
Normal file
23
test/Bitcode/upgrade-tbaa.ll
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
|
||||||
|
|
||||||
|
; Function Attrs: nounwind
|
||||||
|
define void @_Z4testPiPf(i32* nocapture %pI, float* nocapture %pF) #0 {
|
||||||
|
entry:
|
||||||
|
store i32 0, i32* %pI, align 4, !tbaa !{metadata !"int", metadata !0}
|
||||||
|
; CHECK: store i32 0, i32* %pI, align 4, !tbaa [[TAG_INT:!.*]]
|
||||||
|
store float 1.000000e+00, float* %pF, align 4, !tbaa !2
|
||||||
|
; CHECK: store float 1.000000e+00, float* %pF, align 4, !tbaa [[TAG_FLOAT:!.*]]
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
|
|
||||||
|
!0 = metadata !{metadata !"omnipotent char", metadata !1}
|
||||||
|
!1 = metadata !{metadata !"Simple C/C++ TBAA"}
|
||||||
|
!2 = metadata !{metadata !"float", metadata !0}
|
||||||
|
|
||||||
|
; CHECK: [[TAG_INT]] = metadata !{metadata [[TYPE_INT:!.*]], metadata [[TYPE_INT]], i64 0}
|
||||||
|
; CHECK: [[TYPE_INT]] = metadata !{metadata !"int", metadata [[TYPE_CHAR:!.*]]}
|
||||||
|
; CHECK: [[TYPE_CHAR]] = metadata !{metadata !"omnipotent char", metadata !{{.*}}
|
||||||
|
; CHECK: [[TAG_FLOAT]] = metadata !{metadata [[TYPE_FLOAT:!.*]], metadata [[TYPE_FLOAT]], i64 0}
|
||||||
|
; CHECK: [[TYPE_FLOAT]] = metadata !{metadata !"float", metadata [[TYPE_CHAR]]}
|
Loading…
x
Reference in New Issue
Block a user