-
Notifications
You must be signed in to change notification settings - Fork 7
/
AnnotationInfo.cpp
39 lines (32 loc) · 1.05 KB
/
AnnotationInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "AnnotationInfo.h"
#include <llvm/IR/Constants.h>
using namespace llvm;
AnnotationInfo::AnnotationInfo() : ModulePass(ID) {}
bool AnnotationInfo::runOnModule(Module &M) {
return false;
}
bool AnnotationInfo::hasAnnotation(Value *V, StringRef Ann, uint8_t level) {
// Check instruction metadata.
if (auto *I = dyn_cast<Instruction>(V)) {
MDNode *MD = I->getMetadata("tyann");
if (MD) {
auto *MDS = cast<MDString>(MD->getOperand(0));
if (MDS->getString().equals(Ann)) {
auto *CAM = cast<ConstantAsMetadata>(MD->getOperand(1));
auto *CI = cast<ConstantInt>(CAM->getValue());
if (CI->getValue() == level) {
return true;
} else {
return false;
}
}
}
}
// TODO: Check for annotations on globals, parameters.
return false;
}
char AnnotationInfo::ID = 0;
static RegisterPass<AnnotationInfo> X("annotation-info",
"gather type annotations",
false,
true);